#include<reg52.h> //????????????P0?ο??P1λ??//
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
sbit k1=P3^4;
sbit k2=P3^5;
sbit k3=P3^6;
sbit k4=P3^7;
void delayms(uint);
void display(uchar);
void mkcan();
uchar num;
void main()
{
P0=0x00;
P1=0x00;
while(1)
{
mkcan();
}
}
void delayms(uint xms) //???//
{
uint i,j;
for(i=xms;i>0;i--)
for(j=100;j>0;j--);
}
void mkcan()
{
uchar temp,k;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:
k=0;
break;
case 0xde:
k=1;
break;
case 0xbe:
k=2;
break;
case 0x7e:
k=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
display(k);
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:
k=4;
break;
case 0xdd:
k=5;
break;
case 0xbd:
k=6;
break;
case 0x7d:
k=7;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
display(k);
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:
k=8;
break;
case 0xdb:
k=9;
break;
case 0xbb:
k=10;
break;
case 0x7b:
k=11;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
display(k);
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:
k=12;
break;
case 0xd7:
k=13;
break;
case 0xb7:
k=14;
break;
case 0x77:
k=15;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
display(k);
}
}
}
void display(uchar num)
{
P0=table[num];
}
|