پاسخ : دانلود کتابخانه های مختلف برای میکروهای STM
کد:
//951020-------------------------------------- //this sample code are for drive DAC of STM32F103VET6 512k flash 100pin chip void DAC_Configuration(void) { DAC_InitTypeDef DAC_InitStructure; /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* Fill DAC InitStructure */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; /* Select the receiving end */ DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047; /* DAC channel1 Configuration */ DAC_Init(DAC_Channel_2, &DAC_InitStructure); /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.05 is automatically connected to the DAC converter. */ DAC_Cmd(DAC_Channel_2, ENABLE); } void GPIO_Con_DAC(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Configure DAC channe1 and DAC channel2 outputs pins */ // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); } //951020-------------------------------------- int main() { GPIO_Con_DAC(); //init DAC DAC_Configuration(); //init pinout while (1) {static unsigned int daccnt=0; daccnt++; DAC_SetChannel2Data(DAC_Align_12b_R, daccnt); //load DAC data holding register }
دیدگاه