#include "stm32f4xx.h"
#include "exti.h"
#include "key.h"
#include "delay.h"
#include "led.h"
#include "beep.h"
#include "stdio.h"
void EXTI0_IRQHandler(void)
{
printf("EXTI0 coming!
");
if(WK_UP == 1)
{
BEEP = !BEEP;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
void EXTI2_IRQHandler(void)
{
printf("EXTI2 coming!
");
if(KEY2 == 0)
{
LED0 = !LED0;
}
EXTI_ClearITPendingBit(EXTI_Line2);
}
void EXTI3_IRQHandler(void)
{
printf("EXTI3 coming!
");
if(KEY1 == 0)
{
LED1 = !LED1;
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
void EXTI4_IRQHandler(void)
{
printf("EXTI4 coming!
");
if(KEY0 == 0)
{
LED0 = !LED0;
LED1 = !LED1;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
void Exti_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
KEY_Init(); //按键初始化
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE); //使能SYSCFG时钟
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource2); //PE2连接中断线2
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource3); //PE3连接中断线3
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource4); //PE4连接中断线4
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0); //PA0连接中断线0
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line2 |EXTI_Line3 | EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI_Line0; //外部中断0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0X00; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0X02; //响应优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI_Line2;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0X03; //抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0X02; //响应优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI_Line3;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0X02; //抢占优先级2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0X02; //响应优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI_Line4;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0X01; //抢占优先级1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0X02; //响应优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} |