?? key.c
字號:
/*
***************************************************************************************************
* 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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -