#include <AT89X52.H>
#define KeyPort P2
unsigned char KeyLine[4] = {0xef,0xdf};
unsigned char ucKeyScan()
{
unsigned char ucTemp=0;
unsigned char ucRow=0,ucLine=0;
EX0=0;
for(ucLine=0;ucLine<2;ucLine++)
{
KeyPort=KeyLine[ucLine];
ucTemp=KeyPort&0x0F;
if(ucTemp!=0x0F)
{
switch(ucTemp)
{
case 0x0E: ucRow=10;break;
case 0x0D: ucRow=20;break;
case 0x0B: ucRow=30;break;
case 0x07: ucRow=40;break;
default: ucRow=50;break;
}
break;
}
}
KeyPort = 0x0F;
EX0=1;
return ucRow+ucLine+1; /* 返回按键行和列 */
}
仿真文件UART_STC51.rar
文章评论(0条评论)
登录后参与讨论