今天我在配置STM32F103的时候要用到PA5---PA7作为中断,要配置他们的中断函数,但是所有配置都是正常的,自己查不出什么问题,具体代码如下:
void KEY_Init(void) //IO初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//使能PORTA,PORTE时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;//KEY0-KEY1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA 5.6.7
}
void EXITTI_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure; //定义一个EXTI结构体变量
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //使能IO复用功能,使用中断功能重要!!!
KEY_Init();
/* 引脚选择 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource5|GPIO_PinSource6|GPIO_PinSource7);//配置端口C的13引脚为中断源
/* 设置外部中断结构体的成员*/
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断模式为中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿触发
EXTI_InitStructure.EXTI_Line = EXTI_Line5 | EXTI_Line6|EXTI_Line7;
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能中断线
EXTI_Init(&EXTI_InitStructure); //根据参数初始化中断寄存器
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断优先级分组2
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //设定中断源为PC13
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //中断占优先级为2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //副优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能中断
NVIC_Init(&NVIC_InitStructure); //根据参数初始化中断寄存器
}
void EXTI19_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5) != RESET)
{
delay_ms(10);//消抖
if(KEY0==0)
{
printf("555");
LED1=!LED1;
}
/* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line5);
}
else if(EXTI_GetITStatus(EXTI_Line6 )!= RESET)
{
delay_ms(10);//消抖
printf("666");
if(KEY1==0)
{
LED0=!LED0;
/* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line6);
}
else if(EXTI_GetITStatus(EXTI_Line7 )!= RESET)
{
printf("777");
EXTI_ClearITPendingBit(EXTI_Line7);
}
}
|