void Adc_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA |RCC_APB2Periph_ADC1 , ENABLE ); //
//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //PA1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); //
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); //
//
//
//
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; //
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4; //
ADC_CommonInit(&ADC_CommonInitStructure);
//
//
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; //
ADC_InitStructure.ADC_ScanConvMode = DISABLE;//
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //
ADC_InitStructure.ADC_NbrOfConversion = 1; //
ADC_Init(ADC1, &ADC_InitStructure); //
ADC_Cmd(ADC1, ENABLE); //开启ADC
} |