key.c
来自「倒车雷达的原理图与源码」· C语言 代码 · 共 94 行
C
94 行
/*
***************************************************************************************************
* Copyright (C),2007
* Author : YanZhongsan
* Email : yanzhongsan@gmail.com
* Date : 2007-10-17
* File name : HT1621B.c
* Description : HT1621B driver file
* Version : V1.0
* Others : Before any command or read/write ,should initialized the chip by Init_HT1621B
* : function
***************************************************************************************************
*/
/** include files **/
#include "includes.h"
#include "key.h"
/****golbal data****/
UCHAR_8 ButtonFlag;
UCHAR_8 LongKeyFlag;
/*
***************************************************************************************************
* Function name : KeyDriver
* Description : Scanf a singl key
* Note : This routine is a bottom driver, don't call it directly in application routine
* Parameters : keypress: 按键的I/O引脚,据此判断按键是否安下
* : bit:对应于按键的标志位,若该按键的标志在BIT5,则bit应为5
* : sw: 当为1时,将处理长按键,即连续按下时每隔160ms发送一次按键标志,
* : 当为0时,连续按下仅发送一次按键标志
* Returns : None
* Attribute : Private function
* Others : None
***************************************************************************************************
*/
void KeyDriver(UCHAR_8 keypress,UCHAR_8 bit,UCHAR_8 sw)
{
static UCHAR_8 fir_key=0;//按键第一次按下,置位此标志器中对应标志位
static UCHAR_8 sec_key=0;//按键连续按下时,置位此标志器中对应标志位
static UCHAR_8 key_times=0;//记录连续按键
if (keypress)//按键被按下
{
if (TESTBIT(fir_key,bit))//判断是否是连续第二次扫描到此按键
{
if (TESTBIT(sec_key,bit))//判断是否连续(第三次及多次)扫描到按键
{
key_times++;
if ((0x00==key_times%8)&&(0x01==sw))//当处理连续按键时将每隔160ms置位按键标志
{
SETBIT(ButtonFlag,bit);
SETBIT(LongKeyFlag,bit);
}
}
else//不是连续扫描到按键
{
SETBIT(ButtonFlag,bit);
SETBIT(sec_key,bit);
key_times = 0x00;//清空长按键计时器,准备计时
}
}
else
{
SETBIT(fir_key,bit);//第一次扫描到按键
}
}
else
{
CLEARBIT(fir_key,bit);
CLEARBIT(sec_key,bit);
CLEARBIT(LongKeyFlag,bit);
}
}
/*
***************************************************************************************************
* Function name : KeyBoardScanf
* Description : Scanf the keyboard
* Note : This routine is called from interrupt routine only,20ms per second
* Parameters : None
* Returns : None
* Attribute : Public function
* Others : None
***************************************************************************************************
*/
void KeyBoardScanf(void)
{
WDR();
KeyDriver(KEY1PRESSED,KEY1_BIT,0x01);
KeyDriver(KEY2PRESSED,KEY2_BIT,0x01);
KeyDriver(KEY3PRESSED,KEY3_BIT,0x00);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?