#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit k1=P3^4;
sbit k2=P3^5;
sbit k3=P3^6;
sbit k4=P3^7;
uchar key;
uchar code table[]={0x00,0x06,0x5b,0x4f,0x66};
void display(uchar num)
{
P0=table[num];
dula=1;
dula=0;
}
void send(uchar dat)
{
SBUF=dat;
while(!TI);
TI=0;
}
uchar receive(void)
{
uchar dat;
while(RI==0);
RI=0;
dat=SBUF;
return dat;
}
void keyscan()
{
if(k1==0)
key=1;
if(k2==0)
key=2;
if(k3==0)
key=3;
if(k4==0)
key=4;
send(key);
}
void main(void)
{
TMOD=0x20;
SCON=0x50;
PCON=0x00;
TH1=0xf4;
TL1=0xf4;
TR1=1;
REN=1;
P0=0xfe;
wela=1;
wela=0;
P0=0;
dula=1;
dula=0;
while(1)
{
display(receive());
keyscan();
}
}
|