[mw_shl_code=c,true]void Adc_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//ê1ÄüGPIOAê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //ê1ÄüADC1ê±Öó
//Ïè3õê¼»ˉADC1í¨μà5 IO¿ú
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//PA5 í¨μà5
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,ENABLE); //ADC1¸′λ
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1,DISABLE); //¸′λ½áêø
// ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//¶àá¢Ä£ê½
// ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//ὸö2éÑù½×¶ÎÖ®¼äμÄÑó3ù5¸öê±Öó
// ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //DMAê§Äü
//ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;//Ô¤·ÖÆμ4·ÖÆμ¡£ADCCLK=PCLK2/4=84/4=21Mhz,ADCê±Öó×îoÃ2»òa3¬1y36Mhz
// ADC_CommonInit(&ADC_CommonInitStructure);//3õê¼»ˉ
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12λÄ£ê½
// ADC_InitStructure.ADC_ScanDirection=DISABLE;//ADC_ScanConvMode = DISABLE;//·Çé¨ÃèÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//1رÕá¬Dø×a»»
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//½ûÖ1′¥·¢¼ì2a£¬ê1óÃèí¼t′¥·¢
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//óò¶ÔÆë
ADC_InitStructure.ADC_ScanDirection=ADC_ScanDirection_Backward;//ADC_NbrOfConversion = 1;//1¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD1
ADC_Init(ADC1, &ADC_InitStructure);//ADC3õê¼»ˉ
ADC_ChannelConfig(ADC1, ADC_Channel_5 , ADC_SampleTime_55_5Cycles);
ADC_Cmd(ADC1, ENABLE);//¿aÆôAD×a»»Æ÷
} [/mw_shl_code]
[mw_shl_code=c,true]u16 Get_Adc(u8 ch)
{
//éèÖÃÖ¸¶¨ADCμÄ1æÔò×éí¨μ࣬ò»¸öDòáD£¬2éÑùê±¼ä
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_55_5Cycles ); //ADC1,ADCí¨μà,480¸öÖüÆú,ìá¸ß2éÑùê±¼ä¿éòÔìá¸ß¾«è·¶è
ADC_SoftwareStartConv(ADC1); //ê1ÄüÖ¸¶¨μÄADC1μÄèí¼t×a»»Æô¶ˉ1|Äü
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//μè′y×a»»½áêø
return ADC_GetConversionValue(ADC1); //·μ»Ø×î½üò»′ÎADC11æÔò×éμÄ×a»»½á1û
}[/mw_shl_code]
一周热门 更多>