小学生
最后登录1970-1-1
在线时间 小时
注册时间2020-1-15
|
楼主 |
发表于 2020-1-15 16:28:17
|
显示全部楼层
#include "bsp_key.h"
void KEY1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(KEY1_GPIO_CLK,ENABLE);
GPIO_InitStruct.GPIO_Pin=KEY1_GPIO_PIN; //端口配置
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN_FLOATING; //浮空输入模式
GPIO_Init(KEY1_GPIO_PORT, &GPIO_InitStruct); //根据设定参数初始化GPIOA
}
void KEY2_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(KEY2_GPIO_CLK,ENABLE);
GPIO_InitStruct.GPIO_Pin=KEY2_GPIO_PIN; //端口配置
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN_FLOATING; //浮空输入模式
GPIO_Init(KEY2_GPIO_PORT, &GPIO_InitStruct); //根据设定参数初始化GPIOA
}
uint8_t Key_Scan(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==KEY_OFF)
{
while(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==KEY_OFF);
return KEY_OFF;
}
else return KEY_ON;
}
|
|