/*****************key1.c*****************/
#include "key1.h"
#include "main.h"
unsigned char Key_Scan(void)
{
static int count1=0;
static int count2=0;
static int count3=0;
static int count4=0;
char key_value = 0;
/* key1 */
if(B1 == 0)
{
HAL_Delay(10);//去抖
if(B1 == 0)
{
count1++;
}
}
else
{
if(count1 > 40)//长按
{
key_value = 11;
}
if(count1 >=1 && count1<=30)//短按
{
key_value = 1;
}
count1 = 0;//恢复置零
}
/* key2 */
if(B2 == 0)
{
HAL_Delay(10);//去抖
if(B2 == 0)
{
count2++;
}
}
else
{
if(count2> 40)//长按
{
key_value = 22;
}
if(count2 >=1 && count2<=30)//短按
{
key_value = 2;
}
count2 = 0;//恢复置零
}
return key_value;
}
/****************key1.h**************/
#ifndef __KEY1_H_
#define __KEY1_H_
#include "main.h"
unsigned char Key_Scan(void);
//uint8_t KEY_Scan(void);
#define KEY1_PRES 1 //KEY0按下
#define KEY1_LONG_PRES 2 //KEY0长按,长按时间大于1s
#define KEY2_PRES 3 //KEY0按下
#define KEY2_LONG_PRES 4 //KEY0长按,长按时间大于1s
#define KEY3_PRES 5 //KEY0按下
#define KEY3_LONG_PRES 6 //KEY0长按,长按时间大于1s
#define KEY4_PRES 7 //KEY0按下
#define KEY4_LONG_PRES 8 //KEY0长按,长按时间大于1s
#define B1 HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0)
#define B2 HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1)
#define B3 HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2)
#define B4 HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)
#endif