#include "ExtiConfig.h" unsigned char key1Down = 0; unsigned char key2Down = 0; /************************************************************** ** ** ***************************************************************/ void EXTI_Config(void) { EXTI_InitTypeDef extiStruct; NVIC_InitTypeDef nvicStruct; GPIO_InitTypeDef GPIOInit; // NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//先4 从4 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE); //GPIOA 配置 GPIOInit.GPIO_Mode = GPIO_Mode_IPU; //PA0 上拉输入 GPIOInit.GPIO_Pin = GPIO_Pin_3; //LF GPIOInit.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIOInit); GPIOInit.GPIO_Mode = GPIO_Mode_IPU; //PB5 上拉输入 GPIOInit.GPIO_Pin = GPIO_Pin_13; GPIOInit.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIOInit); GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13); extiStruct.EXTI_Line = EXTI_Line3 | EXTI_Line13; extiStruct.EXTI_Mode = EXTI_Mode_Interrupt; extiStruct.EXTI_Trigger = EXTI_Trigger_Falling; extiStruct.EXTI_LineCmd = ENABLE; EXTI_Init(&extiStruct); EXTI_ClearITPendingBit(EXTI_Line3); EXTI_ClearITPendingBit(EXTI_Line13); //外部中断线0,中断复用PA0 nvicStruct.NVIC_IRQChannel = EXTI3_IRQn; nvicStruct.NVIC_IRQChannelPreemptionPriority = 1; nvicStruct.NVIC_IRQChannelSubPriority = 1; nvicStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&nvicStruct); nvicStruct.NVIC_IRQChannel = EXTI15_10_IRQn; nvicStruct.NVIC_IRQChannelPreemptionPriority = 1; nvicStruct.NVIC_IRQChannelSubPriority = 0; nvicStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&nvicStruct); } /************************************************************** ** 外部中断函数,中断线为13 ** ***************************************************************/ void EXTI_Line13IRQ(void) { if(EXTI_GetITStatus(EXTI_Line13)!=RESET) { if(key1Down==0) { key1Down = 1; } EXTI_ClearITPendingBit(EXTI_Line13); //清除 LINE 上的中断标志位 } } /************************************************************** ** 外部中断函数,中断线为13 ** ***************************************************************/ void EXTI_Line3IRQ(void) { if(EXTI_GetITStatus(EXTI_Line3)!=RESET) { if(key2Down==0) { key2Down = 1; } EXTI_ClearITPendingBit(EXTI_Line3); //清除 LINE 上的中断标志位 } }
一些全局的中断标志key1Down和key2Down是为了给工程的其他部分的程序提供一些逻辑。
时间: 2024-11-04 17:38:11