配置8个按键为外部中断,程序写好后接上电连接串口助手还没触发就看到程序立马进入中断永不退出,怎么修改都会卡死在中断,代码如下:[mw_shl_code=c,true]void Exti_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStruvture;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//使能GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //使能复用时钟
//GPIO配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_Init(GPIOA,&GPIO_InitStructure);
//EXTI配置
EXTI_InitStruvture.EXTI_Line = EXTI_Line0|EXTI_Line1|EXTI_Line4|EXTI_Line5|EXTI_Line6|EXTI_Line7|EXTI_Line8|EXTI_Line15;
EXTI_InitStruvture.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruvture.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruvture.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruvture);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0|GPIO_PinSource1|GPIO_PinSource4|GPIO_PinSource5);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource6|GPIO_PinSource7|GPIO_PinSource8|GPIO_PinSource15);
//NVIC配置
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn|EXTI1_IRQn|EXTI4_IRQn|EXTI9_5_IRQn|EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
[/mw_shl_code]
[mw_shl_code=c,true]void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
if(L1==0)
flag4=1;
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
[/mw_shl_code]
[mw_shl_code=c,true]void direction(void)
{
if(flag4==1)
{
printf("%s","BUTTON");
。。。。
}
}[/mw_shl_code]
PS:1.中断处理函数只贴一个因为同样都是设置标志位;2.函数direction都在主函数中执行;
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>