📄 key.c
字号:
#include "ExtDef.h"
uchar xdata RowOut _at_ 0x8000;
uchar xdata ColIn _at_ 0x8003;
uchar Key=Nothing; //键盘缓冲寄存器(公有数据)
uchar Fn_Key; //功能键
extern void delay(int c);
//*********************************************************************
//= 函数原型: void KEYPAD_Scan(char* const Key, char* const Fn_Key)
//= 功 能: 扫描键盘
//= 参 数: 普通键New_Key,功能键New_FuncKey,缓存器的指针
//= 返 回 值:
//= 函数性质:私有函数
//**********************************************************************
void KEYPAD_Scan(char* const Key, char* const Fn_Key)
{
RowOut = 0x70; //Scan Row4
// delay(1);
if ((ColIn&0xF0) == 0xE0) *Fn_Key = 'o'; //ON键
if ((ColIn&0xF0) == 0xD0) *Key = 0;
if ((ColIn&0xF0) == 0xB0) *Fn_Key = '=';
if ((ColIn&0xF0) == 0x70) *Key = '+';
RowOut = 0xB0; //Scan Row3
// delay(1);
if ((ColIn&0xF0) == 0xE0) *Key = 1;
if ((ColIn&0xF0) == 0xD0) *Key = 2;
if ((ColIn&0xF0) == 0xB0) *Key = 3;
if ((ColIn&0xF0) == 0x70) *Key = '-';
RowOut = 0xD0; //Scan Row2
// delay(1);
if ((ColIn&0xF0) == 0xE0) *Key = 4;
if ((ColIn&0xF0) == 0xD0) *Key = 5;
if ((ColIn&0xF0) == 0xB0) *Key = 6;
if ((ColIn&0xF0) == 0x70) *Key = '*';
RowOut = 0xE0; //Scan Row1
// delay(1);
if ((ColIn&0xF0) == 0xE0) *Key = 7;
if ((ColIn&0xF0) == 0xD0) *Key = 8;
if ((ColIn&0xF0) == 0xB0) *Key = 9;
if ((ColIn&0xF0) == 0x70) *Key = '/';
RowOut = 0xF0;
// delay(1);
}
//*********************************************************************
//= 函数原型: void KEY_Update()
//= 功 能: 键盘缓冲寄存器更新程序. 普通键Key, 功能键Fn_Key
//= 参 数:
//= 返 回 值:
//= 函数性质:公有函数
//**********************************************************************
void KEY_Update()
{
static uchar delay=20; //去抖动延时
static bit delaying=0; //标识是否正在延时
if(delaying==0)
{
if(Key==Nothing) //如果Key缓存器中的数据未被读取,则不扫描键盘
{
KEYPAD_Scan(&Key,&Fn_Key); //扫描键盘
if(Key!=Nothing)
{
delaying=1;
Key=Nothing;
}
}
}
else
{
if(delay==0) //延时结束
{
KEYPAD_Scan(&Key,&Fn_Key); //读取键盘
delay=20;
delaying=0;
}
else delay--; //延时减一
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -