本帖最后由 cug_niubosong 于 2017-4-25 09:54 编辑
{
GPIO_InitPara GPIO_InitStructure;
ADC_InitPara ADC_InitStructure;
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AN;
GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClock_Enable( RCC_APB2PERIPH_ADC1, ENABLE);
ADC_InitStructure.ADC_Mode_Scan = DISABLE;
ADC_InitStructure.ADC_Mode_Continuous = DISABLE;
ADC_InitStructure.ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_NONE;
ADC_InitStructure.ADC_Data_Align = ADC_DATAALIGN_RIGHT;
ADC_InitStructure.ADC_Channel_Number = 1;
ADC_Init(&ADC_InitStructure);
ADC_RegularChannel_Config(ADC_CHANNEL_8,1,ADC_SAMPLETIME_55POINT5);
ADC_Enable(ENABLE);
ADC_Calibration();
}
void ADC_Calibration(void)
{
/* Reset the selected ADC1 calibration registers */
ADC1->CTLR2 |= CTLR2_RSTCLB_SET;
/*Check the RSTCLB bit state */
while(ADC1->CTLR2 & CTLR2_RSTCLB_SET);
/* Enable ADC1 calibration process */
ADC1->CTLR2 |= CTLR2_CLB_SET;
/* Check the CLB bit state */
while((ADC1->CTLR2 & CTLR2_CLB_SET) != (u16)RESET);
} |