zoukankan      html  css  js  c++  java
  • 标准库按键中断

    由于中文注释所以插入截图作为参考


    #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ÖжÏÒý½Å RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//ÉèÖÃʱÖÓ GPIO_InitTypeDef button_structer;//¶¨Òå½á¹¹Ìå button_structer.GPIO_Speed = GPIO_Speed_50MHz;//ÉèÖÃÒý½ÅµÃË¢ÐÂËÙ¶È button_structer.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈë button_structer.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOA,&button_structer);//³õʼ»¯GPIOA PA0 //Öжϴ¦Àíº¯Êý ÍⲿÖÐ¶Ï /* 1ÅäÖÃʱÖÓ 2 GPIO¹¤×÷·½Ê½ 3NVICÖжÏÓÅÏȼ¶ (ÓÅÏȼ¶·Ö×飬×Ó/Ö÷ÓÅÏȼ¶¸³Öµ) 4EXTIÍⲿÖжÏÅäÖà (ÅäÖã¬extiʹÄÜ) 5Öжϴ¦Àíº¯Êý*/ //NVICÓÅÏȼ¶ÅäÖà NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);//ÓÅÏȼ¶·Ö×é 0-4ʹ¶ÀÁ¢µÄ 9-5 15-10 NVIC_InitTypeDef nvic; nvic.NVIC_IRQChannelCmd = ENABLE; //ʹÄÜ nvic.NVIC_IRQChannelPreemptionPriority = 0; //Ö÷ÓÅÏȼ¶ÅäÖà 0-15 nvic.NVIC_IRQChannelSubPriority = 0; //×ÓÓÅÏȼ¶ÅäÖà 0 nvic.NVIC_IRQChannel = EXTI0_IRQn; //ÅäÖÃÖжϺŠPA0 Ϊ 0 NVIC_Init(&nvic); //³õʼ»¯ÖÐ¶Ï //ÍⲿÖжÏÅäÖà RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); EXTI_InitTypeDef exti; //ÖжϽṹÌå exti.EXTI_Line = EXTI_Line0; // ͨµÀÏß· exti.EXTI_LineCmd = ENABLE; // ÖжÏʹÄÜ exti.EXTI_Mode = EXTI_Mode_Interrupt; //¹¤×÷ģʽÉèÖÃΪÖжÏģʽ exti.EXTI_Trigger = EXTI_Trigger_Falling; //ϽµÑØ´¥·¢ÖÐ¶Ï EXTI_Init(&exti); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);//°ÑÖжÏÓëÒý½ÅÁ¬½ÓÆðÀ´ //ÅäÖÃPC13ÖжÏÒý½Å RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//ÉèÖÃʱÖÓ GPIO_InitTypeDef button_structer1;//¶¨Òå½á¹¹Ìå button_structer1.GPIO_Speed = GPIO_Speed_50MHz;//ÉèÖÃÒý½ÅµÃË¢ÐÂËÙ¶È button_structer1.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈë button_structer1.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOC,&button_structer1);//³õʼ»¯GPIOA PA0 } void EXTI0_IRQHandler(){//Öжϴ¦Àíº¯Êý 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++); //Çå³ýÖжϱê־λ EXTI_ClearITPendingBit(EXTI_Line0); } } void EXTI15_10_IRQHandler(){//Öжϴ¦Àíº¯Êý 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++); //Çå³ýÖжϱê־λ 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;
    }

    现象

    归去来兮
  • 相关阅读:
    打印一个0到1之间的数的二进制表示
    bzoj-3223 文艺平衡树
    Linux下使用fstatfs/statfs查询系统相关信息
    Pku3664
    hdu-2544 最短路
    java同步包种ArrayBlockingQueue类的分析与理解
    【剑指offer】不用加减乘除做加法
    PA模块经常使用表
    网络编程
    // 插入排序 源代码
  • 原文地址:https://www.cnblogs.com/zoute/p/9314429.html
Copyright © 2011-2022 走看看