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

    防抖时间设的不是太好....

     1 /*
     2 ::按键控制
     3 PA8接LED,PE2接按键
     4 */
     5 #include"stm32f10x.h"
     6 void RCC_Configuration(void);
     7 void GPIO_Config(void);
     8 void Delay(__IO uint32_t nCount);
     9 
    10 int main()
    11 {
    12   RCC_Configuration();                   //系统时钟配置|使能GPIO口
    13   GPIO_Config();                            //LED控制配置
    14   while (1)
    15   {
    16       if(!GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2))
    17     {
    18          Delay(0x000FF);//延时防抖
    19         if(!GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2))
    20         {
    21             GPIO_WriteBit(GPIOA,GPIO_Pin_8,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_8)));
    22         }
    23     }
    24   }
    25 }
    26 /****************************************************************************
    27 * 名    称:void GPIO_Config(void)
    28 * 功    能:GPIO初始化函数
    29 * 入口参数:无
    30 * 出口参数:无
    31 * 说    明:
    32 * 调用方法:无 
    33 ****************************************************************************/ 
    34 void GPIO_Config(void)
    35 {
    36   GPIO_InitTypeDef GPIO_InitStructure;
    37   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;    //配置LEDA8                  
    38   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
    39   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;        
    40   GPIO_Init(GPIOA, &GPIO_InitStructure);
    41   
    42   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;    //配置按键PE2          
    43   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//上拉输入
    44   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;        
    45   GPIO_Init(GPIOE, &GPIO_InitStructure);
    46 }
    47 /****************************************************************************
    48 * 名    称:void RCC_Configuration(void)
    49 * 功    能:系统时钟配置为72MHZ|使能GPIO口
    50 * 入口参数:无
    51 * 出口参数:无
    52 * 说    明:
    53 * 调用方法:无 
    54 ****************************************************************************/ 
    55 void RCC_Configuration(void)
    56 {   
    57   SystemInit();
    58   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOE, ENABLE);//使能GPIO口
    59 }
    60 /****************************************************************************
    61 * 名    称:void Delay(__IO uint32_t nCount)
    62 * 功    能:延时函数
    63 * 入口参数:无
    64 * 出口参数:无
    65 * 说    明:
    66 * 调用方法:无 
    67 ****************************************************************************/ 
    68 void Delay(__IO uint32_t nCount)
    69 {
    70    for(; nCount != 0; nCount--);
    71 }
  • 相关阅读:
    Solr的学习使用之(五)添加索引数据
    django视图层
    django的路由层
    第九章 MySQL 高可用(MHA)
    第八章 mysql的主从复制
    第七章 mysql的备份与恢复
    第六章 mysql日志
    第五章 存储引擎
    第四章 元数据 索引
    第三章 mysql 数据库接口程序以及SQL语句操作
  • 原文地址:https://www.cnblogs.com/zjutlitao/p/3697995.html
Copyright © 2011-2022 走看看