#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp,temp2,aa,bai,shi,ge,num,num1,last,last2,fuhao,ff;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z);
void display(uchar bai, uchar shi, uchar ge);
void init();
uchar keyscan();
void main()
{
num=0;
while(num==0)
{
num=keyscan();
bai=num;
display(bai,0,0);
}
num=0;
while(num==0)
{keyscan();
shi=keyscan();
display(bai,shi,0);
num=0;}
while(num==0)
{ge=keyscan();
display(bai,shi,ge);
num=0;}
last=100*bai+10*shi+ge;
while(num==0){
fuhao=keyscan();
switch(num)
{
case 10:fuhao=10 ; break;
case 11:fuhao=11 ; break;
case 12:fuhao=12 ; break;
case 13:fuhao=13 ; break;
}
num=0;
}
while(num==0)
{keyscan();
bai=keyscan();
display(bai,0,0);
num=0;}
while(num==0)
{keyscan();
shi=keyscan();
display(bai,shi,0);
num=0;}
while(num==0)
{ge=keyscan();
display(bai,shi,ge);
num=0;}
last2=100*bai+10*shi+ge;
delay(10000);
while(num==0)
{
ff=keyscan();
switch(fuhao)
{
case 10:ff=last+last2 ; break;
case 11:ff=last-last2 ; break;
case 12:ff=last*last2 ; break;
case 13:ff=last/last2 ; break;
}
}
bai=ff/100;
shi=ff%100/10;
ge=ff%10;
while(1)
{
display(bai,shi,ge);
}
}
uchar keyscan()
{
P3=0xfe;
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
delay(5);
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
temp2=P3;
switch(temp2)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(temp2!=0xf0)
{
temp2=P3;
temp2=temp2&0xf0;
}
}
}
P3=0xfd;
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
delay(5);
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
temp2=P3;
switch(temp2)
{
case 0xed:num=5;
break;
case 0xdd:num=6;
break;
case 0xbd:num=7;
break;
case 0x7d:num=8;
break;
}
while(temp2!=0xf0)
{
temp2=P3;
temp2=temp2&0xf0;
}
}
}
P3=0xfb;
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
delay(5);
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
temp2=P3;
switch(temp2)
{
case 0xeb:num=9;
break;
case 0xdb:num=10;
break;
case 0xbb:num=11;
break;
case 0x7b:num=12;
break;
}
while(temp2!=0xf0)
{
temp2=P3;
temp2=temp2&0xf0;
}
}
}
P3=0xf7;
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
delay(5);
temp2=P3;
temp2=temp2&0xf0;
while(temp2!=0xf0)
{
temp2=P3;
switch(temp2)
{
case 0xe7:num=13;
break;
case 0xd7:num=14;
break;
case 0xb7:num=15;
break;
case 0x77:num=16;
break;
}
while(temp2!=0xf0)
{
temp2=P3;
temp2=temp2&0xf0;
}
}
}
return num;
}
void display(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff; //消影
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
wela=0;
dula=0;
temp=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
题主,恕我愚昧。我耐心的看完了您的代码,还是不明白您要问什么。。。
楼主没提出问题,是在秀代码吗。。
问题就是代码不好看,没有通假字,算法不给劲!