zoukankan      html  css  js  c++  java
  • stm32 按键

                                        
    //°´¼ü³õʼ»¯º¯Êý
    void KEY_Init(void) //IO³õʼ»¯
    { 
         GPIO_InitTypeDef GPIO_InitStructure;
        //³õʼ»¯KEY0-->GPIOA.13,KEY1-->GPIOA.15  ÉÏÀ­ÊäÈë IPU
         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOE,ENABLE);//ʹÄÜPORTA,PORTEʱÖÓ
    
        GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;//PE2~4
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //ÉèÖóÉÉÏÀ­ÊäÈë
         GPIO_Init(GPIOE, &GPIO_InitStructure);//³õʼ»¯GPIOE2,3,4
    
        //³õʼ»¯ WK_UP-->GPIOA.0      ÏÂÀ­ÊäÈë  IPD
        GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;  //PA0ÉèÖóÉÊäÈ룬ĬÈÏÏÂÀ­      
        GPIO_Init(GPIOA, &GPIO_InitStructure);         //³õʼ»¯GPIOA.0
    
    }
    u8 KEY_Scan(u8 mode)
    {     
        static u8 key_up=1;//°´¼ü°´ËÉ¿ª±êÖ¾
        if(mode)key_up=1;  //Ö§³ÖÁ¬°´          
        if(key_up&&(KEY0==0||KEY1==0||KEY2==0||KEY3==1))  //°´ÏÂÈ¥µÄ״̬key
        {
            delay_ms(10);//È¥¶¶¶¯
            key_up = 0;
                 if(KEY0==0)return KEY_RIGHT;
            else if(KEY1==0)return KEY_DOWN;
            else if(KEY2==0)return KEY_LEFT;
            else if(KEY3==1)return KEY_UP;
        } else if(KEY0==1&&KEY1==1&&KEY2==1&&KEY3==0)key_up=1;         
           return 0;  // ÎÞ°´¼ü°´ÏÂ
    }
        while(1)
        {
             t=KEY_Scan(0);        
               if(t)
            {                           
                switch(t)
                {                 
                    case KEY_UP:    //µÆÈ«Ã𣬷äÃùÆ÷Ïì2Éù          PA.0¿ØÖÆPB.8
                        LED0=1;
                LED1=1;
                    
                     BEEP = 1;
               delay_ms(100);
               BEEP = 0;
               delay_ms(200);
             BEEP = 1;
             delay_ms(100);
               BEEP = 0;
               delay_ms(200);
                        break;
                      case KEY_LEFT:    //LED0ÉÁÒ»´Î  PE.3¿ØÖÆPE.5
                        LED0=0;
                      delay_ms(200);
                      LED0=1;
                        break;
                      case KEY_DOWN:    //¿ØÖÆLED1·­×ª    PE.2¿ØÖÆPB.5
                        LED1=!LED1;
                        break;
                      case KEY_RIGHT:    //ͬʱ¿ØÖÆLED0,LED1·­×ª PE.4
                        LED0=0;
                      delay_ms(200);
                      LED0=1;
                        break;
                }
            }else delay_ms(10); 
        }     
     }
  • 相关阅读:
    [Tutorial] Using the RasPi as a WiFi hostspot
    Turn Your Raspberry Pi Into a WiFi Hotspot with Edimax Nano USB EW-7811Un (RTL8188CUS chipset)
    RPI-Wireless-Hotspot
    将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)
    java的动态代理机制详解
    ant -verbose -debug ...
    各个版本的spring jar包
    挑战树莓派:谁才是Geek最爱的开发板?
    RPi Debian Auto Login
    IP查找工具——angry IP Scanner
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/5325398.html
Copyright © 2011-2022 走看看