按键

key.c

#include "key.h"
void Key_Init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure;
  
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
      //使能时钟

    //B1、B2按键引脚配置
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_8;  
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
      //设置成上拉输入
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    //B3、B4按键引脚配置
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
}

key.h

#ifndef _key_h_
#define _key_h_
#include "sys.h"
#define RB1    GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)
#define RB2    GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8)
#define RB3 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1)
#define RB4 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_2)
uint8_t Key_Scan(void);
void Key_Init(void);
#endif

 

转载于:https://www.cnblogs.com/zhai1997/p/11347479.html

你可能感兴趣的:(按键)