#include "stm32f4xx.h" #include "stm32f4xx_rcc.c" #include "stm32f4xx_dac.c" #include "stm32f4xx_gpio.c" // DAC init function void DACinit (void) { DAC_InitTypeDef DAC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_Init(DAC_Channel_1, &DAC_InitStructure); DAC_Init(DAC_Channel_2, &DAC_InitStructure); DAC_Cmd(DAC_Channel_1, ENABLE); DAC_Cmd(DAC_Channel_2, ENABLE); } int main () { unsigned int j; DACinit(); while (1) { DAC->DHR12R1 = j & 0xfff; // up ramp DAC->DHR12R2 = 0xfff - (j & 0xfff); // down ramp j = (j + 1) & 0x0fff; }; };