#include<at89x51.h>
delay10ms()
{
unsigned char a,b;
for(a=100;a>0;a--)
for(b=50;b>0;b--);
}
delay1ms()
{
unsigned char a,b;
for(a=10;a>0;a--)
for(b=50;b>0;b--);
}
unsigned char code tab[]=
{
0x3f,6,0x5b,0x4f,0x66,0x6d,0x7d,7,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
};
main()
{
unsigned char m,i,j,k,l,p,cc2,cc3,cc4,cc5,o;
unsigned long c1,c2,cc;
unsigned int cc1;
unsigned char aa0,aa1,aa2,aa3,bb0,bb1,bb2,bb3;
unsigned char a0,a1,a2,a3,b0,b1,b2,b3;
bit q,n;
while(1)
{static dian=0x80,fuhao=0;
for (j=0;j<=3;j++)
{
k=0xfe<<j;
l=0xfe>>(8-j);
P0=k|l;
if(P0_4==0)
{
delay10ms();
if(P0_4==0)
{
while(P0_4==0)
{
P2=b0;
P1=0xfe;
delay1ms();
P2=0;
P2=b1;
P1=0xfd;
delay1ms();
P2=0;
P2=b2;
P1=0xfb;
delay1ms();
P2=0;
P2=b3;
P1=0xf7;
delay1ms();
P2=0;
P2=a0;
P1=0xef;
delay1ms();
P2=0;
P2=a1;
P1=0xdf;
delay1ms();
P2=0;
P2=a2;
P1=0xbf;
delay1ms();
P2=0;
P2=a3;
P1=0x7f;
delay1ms();
P2=0;
P2=dian;
P1=0xef;
delay1ms();
P2=0;
P2=fuhao;
P1=0xef;
delay1ms();
P2=0;
}
if(tab[4*j]==0x39)
{
n=1;
i=3;
}
else
{m++;
if(m<=4&n==0)
{
a3=a2;
a2=a1;
a1=a0;
a0=tab[4*j];
aa3=aa2;
aa2=aa1;
aa1=aa0;
aa0=4*j;
}
else
{
if(p<=3&n==1)
{
b3=b2;
b2=b1;
b1=b0;
b0=tab[4*j];
bb3=bb2;
bb2=bb1;
bb1=bb0;
bb0=4*j;
p++;
}
}
}
}
}
if(P0_5==0)
{
delay10ms();
if(P0_5==0)
{
while(P0_5==0)
{
P2=b0;
P1=0xfe;
delay1ms();
P2=0;
P2=b1;
P1=0xfd;
delay1ms();
P2=0;
P2=b2;
P1=0xfb;
delay1ms();
P2=0;
P2=b3;
P1=0xf7;
delay1ms();
P2=0;
P2=a0;
P1=0xef;
delay1ms();
P2=0;
P2=a1;
P1=0xdf;
delay1ms();
P2=0;
P2=a2;
P1=0xbf;
delay1ms();
P2=0;
P2=a3;
P1=0x7f;
delay1ms();
P2=0;
P2=dian;
P1=0xef;
delay1ms();
P2=0;
P2=fuhao;
P1=0xef;
delay1ms();
P2=0;
}
if(tab[4*j+1]==0x5e)
{
i=4;
n=1;
}
else
{m++;
if(m<=4&n==0)
{
a3=a2;
a2=a1;
a1=a0;
a0=tab[4*j+1];
aa3=aa2;
aa2=aa1;
aa1=aa0;
aa0=4*j+1;
}
else
{
if(p<=3&n==1)
{
b3=b2;
b2=b1;
b1=b0;
b0=tab[4*j+1];
bb3=bb2;
bb2=bb1;
bb1=bb0;
bb0=4*j+1;
p++;
}
}
}
}
}
if(P0_6==0)
{
delay10ms();
if(P0_6==0)
{
while(P0_6==0)
{
P2=b0;
P1=0xfe;
delay1ms();
P2=0;
P2=b1;
P1=0xfd;
delay1ms();
P2=0;
P2=b2;
P1=0xfb;
delay1ms();
P2=0;
P2=b3;
P1=0xf7;
delay1ms();
P2=0;
P2=a0;
P1=0xef;
delay1ms();
P2=0;
P2=a1;
P1=0xdf;
delay1ms();
P2=0;
P2=a2;
P1=0xbf;
delay1ms();
P2=0;
P2=a3;
P1=0x7f;
delay1ms();
P2=0;
P2=dian;
P1=0xef;
delay1ms();
P2=0;
P2=fuhao;
P1=0xef;
delay1ms();
P2=0;
}
if(tab[4*j+2]==0x77)
{
i=1;
n=1;
}
else
{
if(tab[4*j+2]==0x79)
{
q=1;
n=1;
}
else
{
m++;
if(m<=4&n==0)
{
a3=a2;
a2=a1;
a1=a0;
a0=tab[4*j+2];
aa3=aa2;
aa2=aa1;
aa1=aa0;
aa0=4*j+2;
}
else
{
if(p<=3&n==1)
{
b3=b2;
b2=b1;
b1=b0;
b0=tab[4*j+2];
bb3=bb2;
bb2=bb1;
bb1=bb0;
bb0=4*j+2;
p++;
}
}
}
}
}
}
if(P0_7==0)
{
delay10ms();
if(P0_7==0)
{
while(P0_7==0)
{
P2=b0;
P1=0xfe;
delay1ms();
P2=0;
P2=b1;
P1=0xfd;
delay1ms();
P2=0;
P2=b2;
P1=0xfb;
delay1ms();
P2=0;
P2=b3;
P1=0xf7;
delay1ms();
P2=0;
P2=a0;
P1=0xef;
delay1ms();
P2=0;
P2=a1;
P1=0xdf;
delay1ms();
P2=0;
P2=a2;
P1=0xbf;
delay1ms();
P2=0;
P2=a3;
P1=0x7f;
delay1ms();
P2=0;
P2=dian;
P1=0xef;
delay1ms();
P2=0;
P2=fuhao;
P1=0xef;
delay1ms();
P2=0;
}
if(tab[4*j+3]==0x71)
{
i=6;
n=1;
}
else
{
if(tab[4*j+3]==0x7c)
{
i=2;
n=1;
}
else
{m++;
if(m<=4&n==0)
{
a3=a2;
a2=a1;
a1=a0;
a0=tab[4*j+3];
aa3=aa2;
aa2=aa1;
aa1=aa0;
aa0=4*j+3;
}
else
{
if(p<=3&n==1)
{
b3=b2;
b2=b1;
b1=b0;
b0=tab[4*j+3];
bb3=bb2;
bb2=bb1;
bb1=bb0;
bb0=4*j+3;
p++;
}
}
}
}
}
}
if(i==6)//复位
{
a0=a1=a2=a3=b0=b1=b2=b3=0;
dian=0x80;
fuhao=0;
m=i=j=k=l=n=p=q=0;
aa0=aa1=aa2=aa3=bb0=bb1=bb2=bb3=0;
c1=c2=cc=cc1=cc2=cc3=cc4=cc5=0;
}
if(q==0)
{
P2=b0;
P1=0xfe;
delay1ms();
P2=0;
P2=b1;
P1=0xfd;
delay1ms();
P2=0;
P2=b2;
P1=0xfb;
delay1ms();
P2=0;
P2=b3;
P1=0xf7;
delay1ms();
P2=0;
P2=a0;
P1=0xef;
delay1ms();
P2=0;
P2=a1;
P1=0xdf;
delay1ms();
P2=0;
P2=a2;
P1=0xbf;
delay1ms();
P2=0;
P2=a3;
P1=0x7f;
delay1ms();
P2=0;
P2=dian;
P1=0xef;
delay1ms();
P2=0;
P2=fuhao;
P1=0xef;
delay1ms();
P2=0;
}
else
{
q=0;
c1=aa0+aa1*10+aa2*100+aa3*1000;
c2=bb0+bb1*10+bb2*100+bb3*1000;
if(i==1)//加法运算
{
cc=c1+c2;
}
if(i==2)//减法运算
{
if(c1>=c2)
{
cc=c1-c2;
}
else
{
cc=c2-c1;
fuhao=0x40;
}
}
if(i==3)//乘法运算
{
cc=c1*c2;
}
a3=tab[cc/10000000];
aa3=cc/10000000;
a2=tab[(cc%10000000)/1000000];
aa2=(cc%10000000)/1000000;
a1=tab[(cc%1000000)/100000];
aa1=(cc%1000000)/100000;
a0=tab[(cc%100000)/10000];
aa0=(cc%100000)/10000;
b3=tab[(cc%10000)/1000];
bb3=(cc%10000)/1000;
b2=tab[(cc%1000)/100];
bb2=(cc%1000)/100;
b1=tab[(cc%100)/10];
bb1=(cc%100)/10;
b0=tab[cc%10];
bb0=cc%10;
dian=0;//消除点
if(aa3==0)//消除多余的零
{
a3=0;
if(aa2==0)
{
a2=0;
if(aa1==0)
{
a1=0;
if(aa0==0)
{
a0=0;
if(bb3==0)
{
b3=0;
if(bb2==0)
{
b2=0;
if(bb1==0)
{
b1=0;
}
}
}
}
}
}
}
if(i==4)//除法运算
{
if(c2==0)
{
for(o=100;o>0;o--)
{
b2=b1=b0=0;
a3=0x79;
a2=a1=b3=0x77;
a0=0x3f;
P2=b0;
P1=0xfe;
delay1ms();
P2=0;
P2=b1;
P1=0xfd;
delay1ms();
P2=0;
P2=b2;
P1=0xfb;
delay1ms();
P2=0;
P2=b3;
P1=0xf7;
delay1ms();
P2=0;
P2=a0;
P1=0xef;
delay1ms();
P2=0;
P2=a1;
P1=0xdf;
delay1ms();
P2=0;
P2=a2;
P1=0xbf;
delay1ms();
P2=0;
P2=a3;
P1=0x7f;
delay1ms();
P2=0;
delay10ms();
}
i=6;
}
else
{
cc1=c1/c2;
a3=tab[cc1/1000];
aa3=cc1/1000;
a2=tab[(cc1%1000)/100];
aa2=(cc1%1000)/100;
a1=tab[(cc1%100)/10];
aa1=(cc1%100)/10;
a0=tab[cc1%10];
aa0=cc1%10;
dian=0x80;
cc2=(c1%c2)*10/c2;
b3=tab[cc2];
cc3=((c1%c2)*10%c2)*10/c2;
b2=tab[cc3];
cc4=(((c1%c2)*10%c2)*10%c2)*10