下面是我写的exti,和例程也没有啥区别啊,可是为什么,为什么按键总是不起效果?
#include "main.h"
void KEY_Configuration(void)
{
GPIO_InitTypeDef gpio;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);//使能PORTA,PORTE时钟
gpio.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_3;//KEY0-KEY1
gpio.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_Init(GPIOE, &gpio);//初始化GPIOE4,3
}
void EXTI_Configuration(void)
{
EXTI_InitTypeDef exti;
NVIC_InitTypeDef nvic;
RCC_APB2PeriphResetCmd( RCC_APB2Periph_AFIO, ENABLE);
//KEY0--PE4
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
exti.EXTI_Line = EXTI_Line4;
exti.EXTI_Mode = EXTI_Mode_Interrupt;
exti.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
exti.EXTI_LineCmd = ENABLE;
EXTI_Init(&exti);
//KEY1--PE3
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource3);
exti.EXTI_Line = EXTI_Line3;
exti.EXTI_LineCmd = ENABLE;
EXTI_Init(&exti);
//KEY0的中断优先级
nvic.NVIC_IRQChannel = EXTI4_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 2;
nvic.NVIC_IRQChannelSubPriority = 1;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
//KEY1的中断优先级
nvic.NVIC_IRQChannel = EXTI3_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 2;
nvic.NVIC_IRQChannelSubPriority = 2;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
}
/**
*函数原型: void EXTI4_IRQHandler(void)
*功 能: KEY0按下,实现LED0的状态翻转
输入参数: 无
输出参数: 无
**/
void EXTI4_IRQHandler(void)
{
//delay_ms(10);
if(KEY0 == 0)
{
LED0 = !LED0;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
//KEY1的中断服务函数
void EXTI3_IRQHandler(void)
{
//delay_ms(10);
if(KEY1 == 0)
{
LED1 = !LED1;
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>