adc.c
void ADC1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//ê1ÄüGPIOAê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//PA0 í¨μà0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;//Ä£Äaêäèë
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;//2»′øéÏÏÂà-
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉ
}
void ADC1_Mode_Config(void)
{
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //ê1ÄüADC1ê±Öó
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_InitStructure.ADC_ScanConvMode = DISABLE;//·Çé¨ÃèÄ£ê½
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//¿aÆôá¬Dø×a»»
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Cmd(ADC1, ENABLE);
}
void ADC_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
}
void Adc_Init(void)
{
ADC1_GPIO_Config();
ADC1_Mode_Config();
ADC_NVIC_Config();
}
extern u16 adcx;
void ADC1_IRQHandler(void)
{
if (ADC_GetITStatus(ADC1,ADC_IT_EOC)==SET)
{
adcx = ADC_GetConversionValue(ADC1);
}
ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);
}
主程序
main.c
u16 adcx=0;
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
uart_init(115200);
LED_Init();
LCD_Init();
Adc_Init();
POINT_COLOR=RED;
while(1)
{
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_56Cycles );
ADC_SoftwareStartConv(ADC1);
LCD_ShowxNum(134,150,adcx,4,16,0);
delay_ms(500);
}
}
一直进不了AD中断,程序貌似会卡在主程序的ADC_SoftwareStartConv(ADC1);
求助~~
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
问题解决了,AD中断的服务函数名称是ADC_IRQHandler,之前一直没查到服务函数的名称,我误以为是ADC1_IRQHandler了,不过还是谢谢你
一周热门 更多>