#include
#define uchar unsigned char
uchar temp;
int key1,key,disbuf;// 此表为 LED 的字模 0 1 2 3 4 5 6 7 8 9 a b c d e f
unsigned char code LED7Code[] = {~0x3F,~0x06,~0x9B,~0x8F,~0xA6,~0xAD,~0xBD,~0x07,~0xBF,~0xAF,~0xB7,~0xBC,~0x39,~0x9E,~0xB9,~0xB1};
void delay(uchar z)
{
uchar i,j;
for(i=0;i<120;i++)
for(j=0;j
void scan() // 要是按键了,扫描键盘编码值
{
P1=0xF0; // P1 4X4 键盘
delay(1);
temp=P1;
switch(temp)
{
case 0xe0: key1=0;
break;
case 0xd0: key1=1;
break;
case 0xb0: key1=2;
break;
case 0x70: key1=3;
break;
}
P1=0x0f;
delay(1);
temp=P1;
switch(temp)
{
case 0x0E: key=key1+0;
break;
case 0x0D: key=key1+4;
break;
case 0x0B: key=key1+8;
break;
case 0x07: key=key1+12;
break;
default : key=-1;
}
if((key1+1)&&(key+1)) disbuf=key;
}
void ejjc() //判断是否按键
{
P1=0xF0;
if(P1!=0xF0)scan();
}
void main()
{
while(1)
{
ejjc();
P3=LED7Code[disbuf]; // P3 显示 89c2051 仿真
delay(200);
}
}