?? 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 + -