📄 keyborad.c
字号:
/*
* Copyright(c)2005 - 2009 danise .China
* All rights reserved.
* Redistribution and use in source and bianry forms
* with or without modification ,are permitted provided
* that following conditions are met:
*
* 1.Redistrubution of source code must retain the
* above copyright notice,this list of conditions and
* following disclaimer.
*
* 2.Redistributions in binary form must reproduce the
* above copyright notice,this list of conditions and
* following disclaimer in the documentation and /or other
* materials provided with the distribution.
*
* Alternately, this acknowledgment may appear in the software
* itself,if and wherever such third-party acknowledgements
* normally appear.
*
* This software is designed for key board and led display.
*
*/
#include"include/keyboard.h"
#include "include/datatypes.h"
#include "include/display.h"
#include "include/global.h"
#include "include/system.h"
/** get key but not a safe key
using P0 port
*/
UINT8 keyok = 0;
UINT8 keyage = 0; /* */
UINT8 oldkey = 0 ;
UINT8 Scankey(void)
{
UINT8 tempkeycode=0xff;
UINT8 AA;
UINT8 BB;
P0=0x0f;
AA=P0;
AA&=0x0f;
BB=AA;
P0=0x0f0;
AA=P0;
AA&=0xf0;
tempkeycode=AA|BB;
return tempkeycode;
}
/*
*/
INT8 GetSafeKeyValue()
{
UINT8 idata temp;
INT8 idata rKeyVal;
temp = Scankey();
if(0xff!=temp){
if(!( temp^oldkey )){/* if same */
oldkey = temp;
keyage ++;
if(! keyok ){ /* never response */
if( keyage == 3 ){
switch ( temp )
{
case 0x77: rKeyVal=0; break;
case 0xBD: rKeyVal=1; break;
case 0xBB: rKeyVal=2; break;
case 0xB7: rKeyVal=3; break;
case 0xED: rKeyVal=4; break;
case 0xEB: rKeyVal=5; break;
case 0xE7: rKeyVal=6; break;
case 0xDD: rKeyVal=7; break;
case 0xDB: rKeyVal=8; break;
case 0xD7: rKeyVal=9; break;
case 0x7B: rKeyVal=10; break;//"."
case 0x7D: rKeyVal=11; break;//"BACK"
case 0xDE: rKeyVal=12; break;//"CLEAR ALL"
case 0xEE: rKeyVal=13; break;//"+"
case 0xBE: rKeyVal=14; break;//"*"
case 0x7E: rKeyVal=15; break;//"enter"
default: rKeyVal=-1;
}
keyok = 1;
keyage = 0;
/* do your work ** begin **with key value */
/* clr crc save */
sreensaveclk = 0;
scrflag = 0;
return rKeyVal ;
/* ** end ** */
}
else{ /*key age is not old enough */
return (-1);
}
}
else{ /* responsed */
return (-1);
}
}
else{/* if different */
keyok = 0;
keyage = 0;
oldkey = temp;
return (-1);
}
}
else{
keyok = 0;
keyage = 0;
return (-1);
}
}
void AnalyseKeyVal(UINT8 keyVal )
{
if (keyVal <0) return; /* no key press */
if(keyVal>=0 && keyVal<=0xa ){
/* data key value */
addKyeValHexBuf( keyVal );
}
else{//>0
/* cmd key value*/
/*
1. LEDS process
2. I2C process
*/
switch ( keyVal )
{
case 11: backspace(); break;
case 12: clearallleds();break;
case 15: enter();break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -