程序现象是8个按键都可以响一遍 但全部按过一遍后 只有UP键 还能响 ;单步调试是发现只在中断15_10处理函数中来回扫描 中断9_5函数一次都不扫描 也不会触发。求大佬说说我哪里出问题了。
//外部中断初始化函数
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);//使能PORTB,PORTC时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//外部中断,需要使能AFIO时钟
KEY_Init();//初始化按键对应io模式
//GPIOC.6 GPIOC.7 GPIOC.8 GPIOC.9 中断线以及中断初始化配置
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource6|GPIO_PinSource7|GPIO_PinSource8|GPIO_PinSource9);
EXTI_InitStructure.EXTI_Line=EXTI_Line6|EXTI_Line7|EXTI_Line8|EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器
//GPIOB.12 GPIOB.13 GPIOB.14 GPIOB.15 中断线以及中断初始化配置
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource12|GPIO_PinSource13|GPIO_PinSource14|GPIO_PinSource15);
EXTI_InitStructure.EXTI_Line=EXTI_Line12|EXTI_Line13|EXTI_Line14|EXTI_Line15;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //使能按键所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能按键所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //子优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
}
void EXTI9_5_IRQHandler(void) //中断处理函数
{
delay_ms(10); //消抖
if(F2==0)
{Beepalarm();EXTI_ClearITPendingBit(EXTI_Line8);} //清除LINE5上的中断标志位
if(DOWN==0)
{Beepalarm();EXTI_ClearITPendingBit(EXTI_Line6);} //清除LINE5上的中断标志位
if(Right==0)
{Beepalarm();EXTI_ClearITPendingBit(EXTI_Line7);} //清除LINE5上的中断标志位
if(ESC==0)
{Beepalarm();EXTI_ClearITPendingBit(EXTI_Line9);} //清除LINE5上的中断标志位
}
void EXTI15_10_IRQHandler(void)
{
delay_ms(10); //消抖
if(MENU==0){Beepalarm();EXTI_ClearITPendingBit(EXTI_Line12); } //清除LINE12线路挂起位
if(F1 ==0){Beepalarm();EXTI_ClearITPendingBit(EXTI_Line13);} //清除LINE12线路挂起位
if(Left==0){Beepalarm();EXTI_ClearITPendingBit(EXTI_Line14);} //清除LINE12线路挂起位
if(UP ==0){Beepalarm(); EXTI_ClearITPendingBit(EXTI_Line15);} //清除LINE12线路挂起位
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
你试下看看行不
一周热门 更多>