📄 keypaddrv.c
字号:
#include "Hal.h"
#include "WatchDog.h"
#include "Delay.h"
#include "LedDrv.h"
#include "LcdMiniDrv.h"
#include "BuzzerDrv.h"
//#include "ZmDebug.h"
/////////////////////////////////////////////////////////////////////
//键盘硬件操作说明:
//__KEY_SIN__全部上拉
//然后全部__KEY_SIN__设为1,全部__KEY_SOUT__设为1
//在__KEY_SOUT__将其中1个设为0,查看__KEY_SIN__中哪个为0,即哪个键有按下
//看__KEY_SOUT__有多少个 即循环多少次
/////////////////////////////////////////////////////////////////////
/*
sbit __KEY_SIN_1__ = P1^0;
sbit __KEY_SIN_2__ = P1^1;
sbit __KEY_SIN_3__ = P1^2;
sbit __KEY_SOUT_1__ = P2^0;
sbit __KEY_SOUT_2__ = P2^1;
sbit __KEY_SOUT_3__ = P2^2;
sbit __KEY_SOUT_4__ = P2^3;
*/
#define _KSI_1 __KEY_SIN_1__
#define _KSI_2 __KEY_SIN_2__
#define _KSI_3 __KEY_SIN_3__
#define _KSO_1 __KEY_SOUT_1__
#define _KSO_2 __KEY_SOUT_2__
#define _KSO_3 __KEY_SOUT_3__
#define _KSO_4 __KEY_SOUT_4__
BOOL _ZmLowLevelGetKey(BYTE * pucKeyIndex)
{
BYTE idata i;
BYTE idata ucP2 = P2;
_KSI_1 = 1;
_KSI_2 = 1;
_KSI_3 = 1;
*pucKeyIndex = 0;
for(i = 0; i < 4; i++)
{
P2 = 0xff;
switch(i)
{
case 0:
_KSO_1 = 0;
break;
case 1:
_KSO_2 = 0;
break;
case 2:
_KSO_3 = 0;
break;
case 3:
_KSO_4 = 0;
break;
}
(*pucKeyIndex)++;
if(!_KSI_1)
goto RetTrue;
(*pucKeyIndex)++;
if(!_KSI_2)
goto RetTrue;
(*pucKeyIndex)++;
if(!_KSI_3)
goto RetTrue;
}
P2 = ucP2;
return FALSE;
RetTrue:
P2 = ucP2;
return TRUE;
}
//code char pstrKeyCode[12] = "1234567890*#";
//code char pstrKeyCode[12] = "789456*0#123"; //for the Old Keypad(ACTR)
//code char pstrKeyCode[12] = "321#0*654987"; //for new designed keypad.
code char pstrKeyCode[12] = "#0*987654321"; //for new designed keypad.
char DecodeKey(BYTE ucKeyIndex)
{
if((ucKeyIndex < 1) || (ucKeyIndex > 12))
return ' ';
return pstrKeyCode[ucKeyIndex-1];
}
//获取键盘的数值,存放在指针pcX所指位置
//为什么不是返回一个字节所获数值的函数??
//为了减少单片机RAM??
BOOL ZmGetKey(char * pcX)
{
BYTE idata ucIndex;
if(_ZmLowLevelGetKey(&ucIndex))
{
*pcX = DecodeKey(ucIndex);
LedOn();
BuzzerKey();
Msec(100);
while(_ZmLowLevelGetKey(&ucIndex))
{
TrigWatchDog();
Msec(150);
}
LedOff();
Msec(50);
return TRUE;
}
return FALSE;
}
//将返回值存放在指针pcX所指位置
BOOL ZmGetKeyDelay(char * pcX) //循环100次访问键盘
{
BYTE idata ucIndex;
BYTE idata i;
for(i = 0; i < 100; i++)
{
if(_ZmLowLevelGetKey(&ucIndex))
{
*pcX = DecodeKey(ucIndex);
LedOn();
BuzzerKey();
Msec(100);
while(_ZmLowLevelGetKey(&ucIndex))
{
TrigWatchDog();
Msec(150);
}
LedOff();
Msec(50);
return TRUE;
}
Msec(50);
}
return FALSE;
}
/*
char _getkey (void)
{
char idata cRt;
for(;;)
{
if(ZmGetKey(&cRt))
return cRt;
TrigWatchDog();
}
}
BOOL ZmGetPassChar(char * pcX)
{
if(ZmGetKeyDelay(pcX))
{
putchar('*');
return TRUE;
}
return FALSE;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -