标签:exti中断程序实例
1 2 3 4 5 6 7 8 9 10 11 | #ifndef __EXTI_H__ #define __EXTI_H__ #include "stm32f10x.h" #include "MyTime.h" #include "bitband.h" void EXTI_Configuration( void ); void EXTI2_IRQHandler( void ) ; #endif |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include "exti.h" #include "key.h" void EXTI_Configuration( void ) { EXTI_InitTypeDef EXTI_InitStruct; NVIC_InitTypeDef NVIC_InitStruct; //1)初始化 IO 口为输入 KEY_Configuration(); //2)开启 IO 口复用时钟,设置 IO 口与中断线的映射关系。 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2); //3)初始化线上中断,设置触发条件等 EXTI_InitStruct.EXTI_Line = EXTI_Line2; EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStruct.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStruct); //4)配置中断分组(NVIC),并使能中断 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 2; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); } //5)编写中断服务函数。 void EXTI2_IRQHandler( void ) { MyDelay_ms(10); //消抖 if (KEY2==0) //按键KEY2 { LED0=!LED0; } EXTI_ClearITPendingBit(EXTI_Line2); //清除 LINE2 上的中断标志位 } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include "MyTime.h" #include "exti.h" int main( void ) { MySysTick_Init(); //点亮灯 GPIO_Configuration(); EXTI_Configuration(); while (1); } |
1 2 3 4 5 | 1)初始化 IO 口为输入。 //KEY_Configuration 2)开启 IO 口复用时钟,设置 IO 口与中断线的映射关系。 3)初始化线上中断,设置触发条件等。 4)配置中断分组(NVIC),并使能中断。 5)编写中断服务函数。 |
标签:exti中断程序实例
原文地址:http://blog.csdn.net/johnsuna/article/details/45130543