NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //这是配置的NVIC
/* Enable the TIM1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; //设置为EXTI5,6,7
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //PD8为检测端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
设置PD8检测下降沿
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource8);
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line8);
}
这是EXTI的设置,中断源是PD8端口
void EXTI9_5_IRQHandler(void)
{
static int n=0;
uchar display[2],i;
if(EXTI_GetITStatus(EXTI_Line8));//!=RESET)
{
n++;
if(n==100)
{
n=0;
}
display[0]=n/10;
display[1]=n%10;
// while(EXTI_GetITStatus(EXTI_Line8))
//{
for(i=0;i<2;i++)
{
LE(0);
GPIO_Write(GPIOA,Disp_Tab[display
]);
LE(1);
switch(i)
{
case 0:LS138A(0),LS138B(0),LS138C(0); break;
case 1:LS138A(1),LS138B(0),LS138C(0); break;
}
Delay(0x1ffff);
}
//}
//while(EXTI_GetITStatus(EXTI_Line8)!=RESET);
EXTI_ClearITPendingBit(EXTI_Line8);
}
}
这是中断处理函数
本意是想把PD8端口与一个独立按键连在一起,之后检测按键按下的次数,在数码管上显示,中断函数中的n是按下次数的记录变量
但是不知道为什么把程序下载下去之后n就一直自加,感觉就是一直在中断函数中一样.....但是一按下按键之后,它就停下来显示了,但是是只显示个位的数字.....之后把中断函数中的“if”改成“while”,之后干脆就不显示了...
是在很费解.....想请大虾给解决一下.....小弟不胜感激