高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-1-3
|
编写STM32程序,按照教程一步步来写,可是两个按键只有一个可以进中断。说明:
KEY1D0;(无法进入中断)
KEY2A8;(程序可以执行中断)
配置代码:
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;//配置中断线结构体
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,GPIO_PinSource0);//配置D.0为中断源
EXTI_InitStructure.EXTI_Line=EXTI_Line0;//挂在0号线上
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;//中断模式
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;//下降沿出发方式
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);//写入配置信息
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource8);//配置A.8为中断源
EXTI_InitStructure.EXTI_Line=EXTI_Line8;//挂在8号线上
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;//中断模式
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;//下降沿出发方式
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);//写入配置信息
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //占先优先级、副优先级的资源分配
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //指定中断源
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //占先优先级设定
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //副优先级设定
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断代码:
extern unsigned char led_bit1,led_bit2;
void EXTI0_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line3) != RESET)
{
if(led_bit2)
{
GPIO_SetBits(GPIOD, GPIO_Pin_7);
led_bit2=0;
}
else
{
GPIO_ResetBits(GPIOD, GPIO_Pin_7);
led_bit2=1;
}
EXTI_ClearFlag(EXTI_Line3);
}
}
void EXTI9_5_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line8) != RESET)
{
if(led_bit1)
{
GPIO_SetBits(GPIOD, GPIO_Pin_6);
led_bit1=0;
}
else
{
GPIO_ResetBits(GPIOD, GPIO_Pin_6);
led_bit1=1;
}
EXTI_ClearFlag(EXTI_Line8);
}
}
在main函数中已经调用中断配置函数了,目前PA8的按键能出发中断,PD0的不可以,二者电路相同。请高人指教。谢谢!
|
|