#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
uchar info[32];
uint temp,num=0,flag=0;
uchar keyscany();
void init();
void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void main()
{
init();
while(1)
{
while(1)
{
info[num]=keyscany();
if(flag>0)
{
while(flag==0);
SBUF=info[num];
num++;
}
if(num==32) break;
}
num=0;
}
}
void init()
{
TMOD=0X20;
TH1=0XFD;
TL1=0XFD;
TR1=1;
SM0=0;
SM1=1;
REN=1;
ES=1;
EA=1;
}
uchar keyscany()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch (temp)
{
case(0xee):num=0;break;
case(0xde):num=1;break;
case(0xbe):num=2;break;
case(0x7e):num=3;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;//???
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch (temp)
{
case(0xed):num=4;break;
case(0xdd):num=5;break;
case(0xbd):num=6;break;
case(0x7d):num=7;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch (temp)
{
case(0xeb):num=8;break;
case(0xdb):num=9;break;
case(0xbb):num=10;break;
case(0x7b):num=11;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch (temp)
{
case(0xe7):num=12;break;
case(0xd7):num=13;break;
case(0xb7):num=14;break;
case(0x77):num=15;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
flag++;
return num;
}
void inter() interrupt 4
{
while(!TI);
TI=0;
} |