各位,刚刚蹙额32 ,我的中断进不去了 帮忙看一下 。多谢
时间:10-02
整理:3721RD
点击:
代码如下 我用小灯检测有没有进入中断,就是进不去 。用万用表测了 我按键按下的时候 A6 电平确实被拉低 了。
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//ía2??D??£?Dèòaê1?üAFIOê±?ó
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource6);
EXTI_InitStructure.EXTI_Line=EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//???μ??′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //?ù?YEXTI_InitStruct?D???¨μ?2?êy3?ê??ˉíaéèEXTI??′??÷
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //ê1?ü°′?ü?ù?úμ?ía2??D??í¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //?à??ó??è??2£?
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //×óó??è??1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1?üía2??D??í¨μà
NVIC_Init(&NVIC_InitStructure);
}
void EXTI9_5_IRQHandler(void)
{
LED0=0;
// if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
// {
// cnt++;
// if(cnt==4000);
// {
//
// TIM_Cmd(TIM3,DISABLE);
// cnt=0;
//
// }
//}
EXTI_ClearITPendingBit(EXTI_Line6);
}
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ê1?üPA,PD???úê±?ó
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //LED0-->PA.8 ???ú????
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //í?íìê?3?
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO?ú?ù?è?a50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //?ù?Yéè?¨2?êy3?ê??ˉGPIOA.8
GPIO_SetBits(GPIOA,GPIO_Pin_6); //PA.8 ê?3???
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //LED0-->PA.8 ???ú????
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //í?íìê?3?
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO?ú?ù?è?a50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //?ù?Yéè?¨2?êy3?ê??ˉGPIOA.8
GPIO_SetBits(GPIOA,GPIO_Pin_0);
}
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//ía2??D??£?Dèòaê1?üAFIOê±?ó
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource6);
EXTI_InitStructure.EXTI_Line=EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//???μ??′¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //?ù?YEXTI_InitStruct?D???¨μ?2?êy3?ê??ˉíaéèEXTI??′??÷
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //ê1?ü°′?ü?ù?úμ?ía2??D??í¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //?à??ó??è??2£?
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //×óó??è??1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1?üía2??D??í¨μà
NVIC_Init(&NVIC_InitStructure);
}
void EXTI9_5_IRQHandler(void)
{
LED0=0;
// if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
// {
// cnt++;
// if(cnt==4000);
// {
//
// TIM_Cmd(TIM3,DISABLE);
// cnt=0;
//
// }
//}
EXTI_ClearITPendingBit(EXTI_Line6);
}
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ê1?üPA,PD???úê±?ó
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //LED0-->PA.8 ???ú????
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //í?íìê?3?
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO?ú?ù?è?a50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //?ù?Yéè?¨2?êy3?ê??ˉGPIOA.8
GPIO_SetBits(GPIOA,GPIO_Pin_6); //PA.8 ê?3???
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //LED0-->PA.8 ???ú????
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //í?íìê?3?
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO?ú?ù?è?a50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //?ù?Yéè?¨2?êy3?ê??ˉGPIOA.8
GPIO_SetBits(GPIOA,GPIO_Pin_0);
}
你是进入中断以后让LED灯灭么?你把PA6配置为推挽输出,推挽输出的电平是不确定的,就是在某个时刻PA6脚的电压可能为低也可能为高(高阻态),就是说在中断之前PA6的电平不确定,建议你把PA6配置为IPU(上拉输入),这样在中断之前电平肯定是高,按键后电平拉低。另外,最好在中断中加一句if(EXTI_GetITStatus(EXTI_Line6)!=RESET),还有复用时钟和JTAG的时钟不用打开