[STM32F1] stm32键不同时长选择不同函数入口

[复制链接]
554|2
 楼主| 捉虫天师 发表于 2017-12-25 19:49 | 显示全部楼层 |阅读模式
主要功能描述:  stm32  中通过按键按下不同时长选择不同的函数入口。这里不同函数入口用亮不同的灯来演示。
软件平台:        keil_MDK422
硬件平台:        stm32开发板(核心芯片stm32f103RB)
固件库版本:     v2.0
  1. /****         main.c       *****/

  2. /* Includes platform dependent ------------------------------------------*/
  3. #include "configuration.h"  // Configuration of the platform
  4. #include "stm32f10x_lib.h"

  5. extern u8   gcKeyCountEnable;
  6. extern u16  gcKeyCnt;

  7. int main(void)
  8. {
  9.      int i = 0;
  10.      ConfigureInterfaces();

  11.      GPIO_KEY_Config();

  12.      LED_config();


  13.     while (1)
  14.     {
  15.        while( IS_KeyDown( GPIO_KEY_PORT, GPIO_KEY1) == 1)
  16.        {
  17.               gcKeyCountEnable = 1;
  18.               if(gcKeyCnt>8) break;
  19.         }
  20.       if(gcKeyCnt > 1 && gcKeyCnt < 3 )
  21.       {
  22.               GPIO_ResetBits(GPIO_LED_RED, GPIO_RED_PIN);
  23.               for(i = 0; i<5000; i++)
  24.               gcKeyCnt = 0 ;
  25.               gcKeyCountEnable = 0;
  26.       }
  27.       else if(gcKeyCnt > 5 )
  28.      {   

  29.              GPIO_ResetBits(GPIO_LED_GREEN , GPIO_GREEN_PIN);
  30.              for(i = 0; i<5000; i++)
  31.              gcKeyCnt = 0 ;
  32.              gcKeyCountEnable = 0;

  33.      }
  34.     else if (gcKeyCnt== 0)
  35.    {  
  36.              GPIO_SetBits(GPIO_LED_GREEN , GPIO_GREEN_PIN);
  37.              GPIO_SetBits(GPIO_LED_RED , GPIO_RED_PIN);
  38.     }

  39.   }

  40. }



  41. /******     st32mf10x_it.c     *******/



  42. void TIM2_IRQHandler(void)
  43. {
  44.     if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)

  45.     {
  46.         TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  47.         
  48.          if( gcKeyCountEnable==1 )

  49.         gcKeyCnt ++;        
  50.      }
  51. }


wahahaheihei 发表于 2017-12-25 21:01 | 显示全部楼层
好东西,学习怎么通过按键时间控制了。
dongnanxibei 发表于 2017-12-26 10:58 | 显示全部楼层
这个方法不错,学习了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

213

主题

3276

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部