void ADC1_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOA Periph clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOC, ENABLE);
/* ADC1 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* Configure ADC Channel11 as analog input */
/* Configure PA.01 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ADCs DeInit */
ADC_DeInit(ADC1);
/* Initialize ADC structure */
ADC_StructInit(&ADC_InitStructure);
/* Configure the ADC1 in continuous mode with a resolution equal to 12 bits */
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Backward;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1);
/* Enable the ADC peripheral */
ADC_Cmd(ADC1, ENABLE);
/* Wait the ADRDY flag */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
// ADC_GetCalibrationFactor(ADC1);
// while(ADC_GetCalibrationFactor(ADC1)); //µÈ´ýУ׼½áÊø //ADC
/* ADC1 regular Software Start Conv */
//ADC_StartOfConversion(ADC1);
}
u16 Get_Adc(u32 ch)
{
//ÉèÖÃÖ¸¶¨ADCµÄ¹æÔò×éͨµÀ£¬Ò»¸öÐòÁУ¬²ÉÑùʱ¼ä
ADC_ChannelConfig(ADC1, ch , ADC_SampleTime_239_5Cycles); //ADC1,ADCͨµÀ,²ÉÑùʱ¼äΪ239.5ÖÜÆÚ
ADC_StartOfConversion(ADC1); //ʹÄÜÖ¸¶¨µÄADC1µÄÈí¼þת»»Æô¶¯¹¦ÄÜ
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//µÈ´ýת»»½áÊø
return ADC_GetConversionValue(ADC1); //·µ»Ø×î½üÒ»´ÎADC1¹æÔò×éµÄת»»½á¹û
}
多通道感觉切换了就感觉通道的数据乱了,
ADC_ConvertedValueLocal = Get_Adc(SH_CH1);
printf(" Ò» %d " , ADC_ConvertedValueLocal);
OSTimeDly(200);
//
// OSTimeDly(200);
// ADC_ConvertedValueLocal = Get_Adc(SH_CH2);
// OSTimeDly(200);
//
// printf(" ¶þ %d " , ADC_ConvertedValueLocal);
// OSTimeDly(200);
// for(sh_count=0;sh_count<10;sh_count++){
// ADC_ConvertedValueLocal = Get_Adc(SH_CH3);
// OSTimeDly(200);
// printf(" Èý %d " , ADC_ConvertedValueLocal);
// OSTimeDly(1000);
// }
//
// for(sh_count=0;sh_count<10;sh_count++){
// ADC_ConvertedValueLocal = Get_Adc(SH_CH4);
// OSTimeDly(200);
// printf(" ËÄ %d " , ADC_ConvertedValueLocal);
// OSTimeDly(1000);
这是主程序里的,思科通道,OSTIMEDLY 是延时 |