標準庫按鍵中斷
阿新 • • 發佈:2018-07-15
prior nec handler style fall bsp 中文註釋 cte ins
由於中文註釋所以插入截圖作為參考
#include "stm32f10x_it.h" #include "stm32f10x_gpio.h" #include "stm32f10x.h" #include "stm32f10x_exti.h" #include "Button.h" #include "Led.h" void init_Button(){ //????PA0?D??òy?? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//éè??ê±?ó GPIO_InitTypeDef button_structer;//?¨ò??á11ì? button_structer.GPIO_Speed = GPIO_Speed_50MHz;//éè??òy??μ??¢D??ù?è button_structer.GPIO_Mode = GPIO_Mode_IN_FLOATING; //????ê?è? button_structer.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOA,&button_structer);//3?ê??ˉGPIOA PA0 //?D??′|àíoˉêy ía2??D?? /* 1????ê±?ó 2 GPIO1¤×÷·?ê? 3NVIC?D??ó??è?? (ó??è??·?×é£?×ó/?÷ó??è???3?μ) 4EXTIía2??D?????? (????£?extiê1?ü) 5?D??′|àíoˉêy*/ //NVICó??è?????? NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);//ó??è??·?×é 0-4ê1?àá¢μ? 9-5 15-10 NVIC_InitTypeDef nvic; nvic.NVIC_IRQChannelCmd = ENABLE; //ê1?ü nvic.NVIC_IRQChannelPreemptionPriority = 0; //?÷ó??è?????? 0-15 nvic.NVIC_IRQChannelSubPriority = 0; //×óó??è?????? 0 nvic.NVIC_IRQChannel = EXTI0_IRQn; //?????D??o? PA0 ?a 0 NVIC_Init(&nvic); //3?ê??ˉ?D?? //ía2??D?????? RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); EXTI_InitTypeDef exti; //?D???á11ì? exti.EXTI_Line = EXTI_Line0; // í¨μà???· exti.EXTI_LineCmd = ENABLE; // ?D??ê1?ü exti.EXTI_Mode = EXTI_Mode_Interrupt; //1¤×÷?£ê?éè???a?D???£ê? exti.EXTI_Trigger = EXTI_Trigger_Falling; //???μ??′¥·¢?D?? EXTI_Init(&exti); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);//°??D??ó?òy??á??ó?eà′ //????PC13?D??òy?? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//éè??ê±?ó GPIO_InitTypeDef button_structer1;//?¨ò??á11ì? button_structer1.GPIO_Speed = GPIO_Speed_50MHz;//éè??òy??μ??¢D??ù?è button_structer1.GPIO_Mode = GPIO_Mode_IN_FLOATING; //????ê?è? button_structer1.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOC,&button_structer1);//3?ê??ˉGPIOA PA0 } void EXTI0_IRQHandler(){//?D??′|àíoˉêy int i; if(EXTI_GetFlagStatus(EXTI_Line0) != RESET){ Led_Red_On(); for(i = 0;i<1000000;i++); Led_Red_Off(); for(i = 0;i<1000000;i++); //??3y?D??±ê???? EXTI_ClearITPendingBit(EXTI_Line0); } } void EXTI15_10_IRQHandler(){//?D??′|àíoˉêy int i; if(EXTI_GetFlagStatus(EXTI_Line0) != RESET){ Led_Red_On(); for(i = 0;i<1000000;i++); Led_Red_Off(); for(i = 0;i<1000000;i++); //??3y?D??±ê???? EXTI_ClearITPendingBit(EXTI_Line0); } }
主函數運行
#include "stm32f10x_it.h" #include "stm32f10x_gpio.h" #include "stm32f10x.h" #include "Led.h" #include "Button.h" #include "Uart.h" int main(){ init_Button();//按鍵初始化 while(1); return 0; }
現象
標準庫按鍵中斷