#include<reg52.h>
#define uchar unsigned char
sbit wei1=P3^0;
sbit wei2=P3^1;
sbit wei3=P3^6;
sbit wei4=P3^7;
uchar code numh[11]={
0xbf,//0
0x86,//1
0xdb,//2
0xcf,
0xe6,
0xed,
0xfd,
0x87,
0xff,
0xef,//9
0x00
};
uchar code numl[11]={
0x3f,//0
0x06,//1
0x5b,//2
0x4f,
0x66,
0x6d,
0x7d,
0x07,
0x7f,
0x6f,//9
0x00
};
uchar i,num,f,shu1,shu2,shu3,shu4,temp=50;
void delay(uchar j)
{
uchar i=0;
for(j;j;j--)
for(i=0;i<110;i++);
}
display()
{ P2=numh[shu1];
wei1=0;wei2=wei3=wei4=1;
delay(10);
P2=0;
P2=numl[shu2];
wei2=0;wei1=wei3=wei4=1;
delay(10);
P2=0;
P2=numl[shu3];
wei3=0;wei1=wei2=wei4=1;
delay(10);
P2=0;
P2=numl[shu4];
wei4=0;wei1=wei2=wei3=1;
delay(10);
P2=0;
}
void main()
{ f=0; shu1=shu2=shu3=shu4=0;
num=0x00;
while(1)
{
P1=0xfe;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
if(temp!=0xf0)
switch(temp)
{
case 0xe0:num=1;f++;while(P1==0xee);
break;
case 0xd0:num=2;f++;while(P1==0xde);
break;
case 0xb0:num=3;f++;while(P1==0xbe);
break;
case 0x70:num=0x0c;f++;while(P1==0x7e);
break;
}
}
P1=0xfd;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
if(temp!=0xf0)
switch(temp)
{
case 0xe0:num=4;f++;while(P1==0xed) ;
break;
case 0xd0:num=5;f++; while(P1==0xdd) ;
break;
case 0xb0:num=6;f++; while(P1==0xbd) ;
break;
case 0x70:num=0x0d;f++;while(P1==0x7d) ;
break;
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
if(temp!=0xf0)
switch(temp)
{
case 0xe0:num=7;f++;while(P1==0xeb) ;
break;
case 0xd0:num=8;f++; while(P1==0xdb) ;
break;
case 0xb0:num=9;f++;while(P1==0xbb) ;
break;
case 0x70:num=0x0e;f++;while(P1==0x7b) ;
break;
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
switch(temp)
{
case 0xe0: num=0x0a;f++ ;while(P1==0xe7) ;
break;
case 0xd0: num=0;f++; while(P1==0xd7) ;
break;
case 0xb0: num=0x0b;f++; while(P1==0xb7) ;
break;
case 0x70: num=0x0f;f++; while(P1==0x77) ;
break;
}
}
if(num==0x0c){shu1=shu2=shu3=shu4=0;display(); f=0;wei4=1;}
else if(f==1)
{ shu1=num;P2=numl[shu1];wei1=0;wei2=wei3=wei4=1;delay(10);
}
else if(f==2)
{ if(num==0x0a)
{ P2=numh[shu1];
wei1=0;wei2=wei3=wei4=1;
delay(10);
P2=0; }
else if(num!=0x0a)f--;
}
else if(f==3)
{shu2=num;
P2=numh[shu1];
wei1=0;wei2=wei3=wei4=1;
delay(10);
P2=0;
P2=numl[shu2];
wei2=0;wei1=wei3=wei4=1;
delay(10);
P2=0;}
else if(f==4)
{shu3=num;
P2=numh[shu1];
wei1=0;wei2=wei3=wei4=1;
delay(10);
P2=0;
P2=numl[shu2];
wei2=0;wei1=wei3=wei4=1;
delay(10);
P2=0;
P2=numl[shu3];
wei3=0;wei1=wei2=wei4=1;
delay(10);
P2=0;}
else if(f==5)
{shu4=num;
P2=numh[shu1];
wei1=0;wei2=wei3=wei4=1;
delay(10);
P2=0;
P2=numl[shu2];
wei2=0;wei1=wei3=wei4=1;
delay(10);
P2=0;
P2=numl[shu3];
wei3=0;wei1=wei2=wei4=1;
delay(10);
P2=0;
P2=numl[shu4];
wei4=0;wei1=wei2=wei3=1;
delay(10);
P2=0;}
else if(f==6&num==0x0b)
{
delay(10);
f=0;
display();
if(shu3>=5){shu2++;
P0=shu1*10+shu2;
shu2--;}
P0=shu1*10+shu2;
}
else if(f==0){display();}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>