#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar a=0,b=0,c=0,d=0;
sbit d1=P3^0;
sbit d2=P3^1;
sbit d3=P3^4;
sbit d4=P3^5;
sbit d5=P3^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint code table1[]={
0,248,249,250,
250,251,251,252,
252,252,253,253,
253,253,254 };
uint code table2[]={
0,136, 62, 19,
104, 5,144, 12,
68,209, 9, 52,
130,200, 6 };
uchar table3[80];
uchar qm;
uchar mm,nn;
void display(uchar a,uchar b,uchar c,uchar d);
void delay(uint z);
void yinyue(uchar q);
uchar key(void);
void fangyin(void);
void lvyin(void);
void main(void)
{
uchar a1;
table3[0]=15;
display(a,b,c,d);
EA=1;
EX0=1;
EX1=1;
IP=0x08;
IT0=0;
IT1=0;
while(1)
{
table3[79]=15;
d2=1;
d3=0;
d4=0;
d5=0;
nn=17;
display(a,b,c,d);
P2=0xf0;
mm=P2;
mm=(mm&0xf0);
if(mm!=0xf0)
{
nn=key();
if(nn<=16)
{
d=c;
c=b;
b=a;
a=nn;
}
}
if(nn<=14)
{
yinyue(nn);
nn=0;
}
if(nn==15)
{
d3=1;
mm=0xf0;
while(mm==0xf0)
{
while(mm==0xf0)
{
;P2=0xf0;
mm=P2;
mm=(mm&0xf0);
display(a,b,c,d);
}
display(a,b,c,d);
;P2=0xf0;
mm=P2;
mm=(mm&0xf0);
}
a1=0;
while(a1<=250)
{
a1++;
display(a,b,c,d);
P2=0xf0;
mm=P2;
mm=(mm&0xf0);
if(mm==0xf0)
{
d3=1;
a1=253;
}
}
if(a1<=252)
{
display(a,b,c,d);
d3=0;
d4=1;
lvyin();
d4=0;
display(a,b,c,d);
display(a,b,c,d);
display(a,b,c,d);
}
if(a1>=253)
{
display(a,b,c,d);
d3=0;
d5=1;
fangyin();
d5=0;
display(a,b,c,d);
display(a,b,c,d);
display(a,b,c,d);
}
d3=0;
}
}
}
void yinyue(uchar q)
{
uint jia;
uchar ce;
TMOD=0x10;
ET1=1;
qm=q;
TH1=(65536-table1[q])/256;
TL1=(65536-table1[q])%256;
display(a,b,c,d);
if(q!=0)
{TR1=1;}
if(q==0)
{TR0=0;}
for(jia=0;jia<=300;jia++)
{
P2=0xf0;
ce=P2;
ce=(ce&0xf0);
if(ce!=0xf0)
jia=301;
display(a,b,c,d);
}
TR1=0;
}
void time1() interrupt 3
{ TH1=table1[qm];
TL1=table2[qm];
d1=~d1;
}
void display(uchar a,uchar b,uchar c,uchar d)
{
P0=0xff;
;P1=table[a];
;P0=0xfe;
delay(1);
;P0=0xff;
;P1=table;
;P0=0xfd;
delay(1);
;P0=0xff;
;P1=table[c];
;P0=0xfb;
delay(1);
P0=0xff;
P1=table[d];
P0=0xf7;
delay(1);
P0=0xff;
}
void delay(uint z)
{ uchar p,qq;
for(p=0;p<=z;p++)
for(qq=0;qq<=57;qq++);
}
uchar key(void)
{ uchar hu,num;
display(a,b,c,d);
display(a,b,c,d);
display(a,b,c,d);
P2=0xf0;
hu=P2;
hu=(hu&0xf0);
if(hu==0xf0)
num=17;
if(hu!=0xf0)
{
P2=0xfe;
hu=P2;
hu=(hu&0xf0);
switch(hu)
{
case 0xe0:num=3;
break;
case 0xd0:num=2;
break;
case 0xb0:num=1;
break;
case 0x70:num=0;
break;
}
P2=0xfd;
hu=P2;
hu=(hu&0xf0);
switch(hu)
{
case 0xe0:num=7;
break;
case 0xd0:num=6;
break;
case 0xb0:num=5;
break;
case 0x70:num=4;
break;
}
P2=0xfb;
hu=P2;
hu=(hu&0xf0);
switch(hu)
{
case 0xe0:num=11;
break;
case 0xd0:num=10;
break;
case 0xb0:num=9;
break;
case 0x70:num=8;
break;
}
P2=0xf7;
hu=P2;
hu=(hu&0xf0);
switch(hu)
{
case 0xe0:num=15;
break;
case 0xd0:num=14;
break;
case 0xb0:num=13;
break;
case 0x70:num=12;
break;
}
P2=0xf0;
hu=P2;
while(hu!=0xf0)
{
P2=0xf0;
hu=P2;
display(a,b,c,d);
display(a,b,c,d);
while(hu!=0xf0)
{ display(a,b,c,d);
P2=0xf0;
hu=P2;
}
}
}
return num;
}
void int0() interrupt 0
{
yinyue(0);
yinyue(1);
yinyue(2);
yinyue(3);
yinyue(4);
yinyue(5);
yinyue(6);
yinyue(7);
yinyue(8);
yinyue(9);
yinyue(10);
yinyue(11);
yinyue(12);
yinyue(13);
yinyue(14);
}
void int1() interrupt 2
{
yinyue(0);
yinyue(1);
yinyue(1);
yinyue(2);
yinyue(4);
yinyue(3);
yinyue(1);
yinyue(1);
yinyue(2);
yinyue(1);
yinyue(5);
yinyue(4);
yinyue(1);
yinyue(1);
yinyue(6);
yinyue(4);
yinyue(3);
yinyue(2);
yinyue(7);
yinyue(7);
yinyue(6);
yinyue(4);
yinyue(5);
yinyue(4);
yinyue(0);
yinyue(1);
yinyue(1);
yinyue(2);
yinyue(4);
yinyue(3);
yinyue(1);
yinyue(1);
yinyue(2);
yinyue(1);
yinyue(5);
yinyue(4);
yinyue(1);
yinyue(1);
yinyue(6);
yinyue(4);
yinyue(3);
yinyue(2);
yinyue(7);
yinyue(7);
yinyue(6);
yinyue(4);
yinyue(5);
yinyue(4);
}
void lvyin(void)
{ uchar c1=0,c2=0;
P2=0xf0;
mm=P2;
mm=(mm&0xf0);
display(a,b,c,d);
while(mm!=0xf0)
{
while(mm!=0xf0)
{
P2=0xf0;
mm=P2;
mm=(mm&0xf0);
display(a,b,c,d);
}
display(a,b,c,d);
P2=0xf0;
mm=P2;
mm=(mm&0xf0);
}
while(c2!=15)
{ display(a,b,c,d);
P2=0xf0;
mm=P2;
mm=(mm&0xf0);
if(mm!=0xf0)
{
nn=key();
if(nn<=15)
{
table3[c1]=nn;
d=c;
c=b;
b=a;
a=nn;
c2=nn;
yinyue(nn);
display(a,b,c,d);
c1++;
}
}
}
}
void fangyin(void)
{
uchar c4=0,c5=0;
while(c4!=15)
{
c4=table3[c5];
d=c;
c=b;
b=a;
a=c4;
display(a,b,c,d);
yinyue(c4);
c5++;
}
}
|