经测试KEY_UP能进入中断,其余进不了中断#include "exti.h"
#include "stm32f4xx.h"
#include "delay.h"
#include "key.h"
#include "led.h"
#include "beep.h"
void My_EXTI_Init(void)
{
EXTI_InitTypeDef EXTI_st;
NVIC_InitTypeDef NVIC_st;
delay_init(168);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG,ENABLE);//使能SYSCFG时钟
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOE,ENABLE);//使能GPIO时钟
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_GPIOA,ENABLE);
//GPIOE4 KEY0
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource4);
EXTI_st.EXTI_Line = EXTI_Line4;
EXTI_st.EXTI_LineCmd = ENABLE;
EXTI_st.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_st.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_st);//初始化中断4
NVIC_st.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_st.NVIC_IRQChannelCmd = ENABLE;
NVIC_st.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级0
NVIC_st.NVIC_IRQChannelSubPriority = 2;//响应优先级2
NVIC_Init(&NVIC_st);
//GPIOE3 KEY1
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource3);
EXTI_st.EXTI_Line = EXTI_Line3;
EXTI_st.EXTI_LineCmd = ENABLE;
EXTI_st.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_st.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_st);//初始化中断3
NVIC_st.NVIC_IRQChannel = EXTI3_IRQn;
NVIC_st.NVIC_IRQChannelCmd = ENABLE;
NVIC_st.NVIC_IRQChannelPreemptionPriority = 1;//抢占优先级1
NVIC_st.NVIC_IRQChannelSubPriority = 2;//响应优先级2
NVIC_Init(&NVIC_st);//配置分组
//GPIOE2 KEY2
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource2);
EXTI_st.EXTI_Line = EXTI_Line2;
EXTI_st.EXTI_LineCmd = ENABLE;
EXTI_st.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_st.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_st);//初始化中断2
NVIC_st.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_st.NVIC_IRQChannelCmd = ENABLE;
NVIC_st.NVIC_IRQChannelPreemptionPriority = 2;//抢占优先级2
NVIC_st.NVIC_IRQChannelSubPriority = 2;//响应优先级2
NVIC_Init(&NVIC_st);//配置分组
//GPIOA0 KEY_UP
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);
EXTI_st.EXTI_Line = EXTI_Line0;
EXTI_st.EXTI_LineCmd = ENABLE;
EXTI_st.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_st.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_Init(&EXTI_st);//初始化中断0
NVIC_st.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_st.NVIC_IRQChannelCmd = ENABLE;
NVIC_st.NVIC_IRQChannelPreemptionPriority = 3;//抢占优先级3
NVIC_st.NVIC_IRQChannelSubPriority = 2;//响应优先级2
NVIC_Init(&NVIC_st);//配置分组
}
void EXTI4_IRQHandler()//中断4服务函数
{
delay_ms(10);
if(KEY0 == 0)
{
LED0 = !LED0;
LED1 = !LED1;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
void EXTI3_IRQHandler()//中断3服务函数
{
delay_ms(10);
if(KEY1 == 0)
{
LED1 = !LED1;
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
void EXTI2_IRQHandler()//中断2服务函数
{
delay_ms(10);
if(KEY2 == 0)
{
LED0 = !LED0;
}
EXTI_ClearITPendingBit(EXTI_Line2);
}
void EXTI0_IRQHandler()//中断1服务函数
{
delay_ms(10);
if(KEY_UP == 1)
{
BEEP = !BEEP;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
键盘所对的引脚上面有写
一周热门 更多>