设计IO中断作为按键输入,但是程序不响应中断,哪位大侠帮忙分析一下原因,代码如下:
void test_KEY0_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void test_key_0(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
// EXTI_ClearITPendingBit(EXTI_PinSource0);
EXTI_InitStruct.EXTI_Line = EXTI_PinSource0;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
//=============================================================================
//文件名称:EXTI0_1_IRQHandler
//功能概要:按键中断处理函数,
//参数说明:无
//函数返回:无
//=============================================================================
void EXTI0_1_IRQHandler(void)
{
if ( EXTI_GetITStatus(EXTI_Line0)!= RESET )
{
LED_TURN;
EXTI_ClearITPendingBit(EXTI_Line0);
}
if ( EXTI_GetITStatus(EXTI_Line1)!= RESET )
{
LED_TURN;
EXTI_ClearITPendingBit(EXTI_Line1);
}
int main(void)
{
// LED_Init();
test_key_0();
test_KEY0_Init();
while(1)
} |