求教:新手编的计算器软件,有bug,请大神指点!
新手求教:摁125会出-等4个bug,什么地方出问题了:#include<reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit RS=P3^5;
sbit RW=P3^6;
sbit EN=P3^4;
sbit duan=P2^6;
sbit wei=P2^7;
idata signed long d,f[10],jg;
idata uchar flag=0,j=0,c=0;
bit flag1=0,flag2=0;
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}
void read_busy()
{
uchar busy;
P0=0xff;
RS=0;
RW=1;
do
{
EN=1;
busy=P0;
EN=0;
}
while(busy&0x80);
}
void write_cmd(uchar cmd)
{
read_busy();
RS=0;
RW=0;
P0=cmd;
EN=1;
EN=0;
}
void write_dat(uchar dat)
{
read_busy();
RS=1;
RW=0;
P0=dat;
EN=1;
EN=0;
}
void write_zfc(uchar x,uchar y,uchar *zfc)
{
if(y) x|=0x40;
x|=0x80;
write_cmd(x);
while(*zfc!='\0')
{
write_dat(*zfc++);
delay(150);
}
}
void write_zf(uchar x,uchar y,uchar dat)
{
if(y) x|=0x40;
x|=0x80;
write_cmd(x);
write_dat(dat);
}
void init()
{
duan=0;
wei=0;
write_cmd(0x38);
write_cmd(0x01);
write_cmd(0x0c);
write_cmd(0x06);
}
jianpan0()
{
uchar cord_l,cord_h;
P3 = 0xf0;
if( (P3 & 0xf0) != 0xf0)
{
delay(10);
if( (P3 & 0xf0) != 0xf0)
{
cord_l = P3 & 0xf0;
P3 = cord_l | 0x0f;
cord_h = P3 & 0x0f;
while( (P3 & 0x0f) != 0x0f );
return (cord_l + cord_h);
}
}
}
void shuchu(uchar i)
{
uchar b[]={0x00,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x2b,0x2a,0x2f,0x2d,0x3d,0x20};//0,1,2,3,4,5,6,7,8,9,+,*,\,-,.,=
uchar out[]={"out"};
if(i!=0)
{
if(c>15)
{
write_cmd(0x18);
}
if(c==38)
{
write_cmd(0x01);
write_zfc(0,0,&out[0]);
write_cmd(0x08);
c=0;
init();
d=0;jg=0;for(j=0;j<10;j++){f[j]=0;}flag=0;j=0;flag1=0;i=0;
}
else{
write_zf(c,0,b[i]);
c++;
delay(10);}
}
}
void shuchu1(signed long f)
{
uchar e[10];
uint i=0;
if(f<0)
{
f=-f;
shuchu(14);
}
if(f==0)
{
shuchu(1);
}
if(f>0)
{
while(f!=0)
{
e[i++]=(long int)f%10;
(long int)f/=10;
}
i=i-1;
while(i!=-1)
{
if(c==38){break;}
shuchu((e[i--]+1));
delay(50);
}
}
}
void gongneng(flag,d)
{
switch(flag)
{
case 0:f[j]=d;break;
case 1:f[j]=d;break;
case 2:f[j]=-d;break;
case 3:f[j-1]=f[j-1]*d;j--;break;
case 4:if(d==0){c=38;}
f[j-1]=f[j-1]/d;j--;break;
}
if(!flag1){j++;}flag1=0;
}
void jianpan()
{
uchar a=0,b=0;
switch( jianpan0() )
{
case 0xee:if(flag1){shuchu(11);flag1=0;}shuchu(8);a=7;d=10*d+a;flag2=0;break;
case 0xde:if(flag1){shuchu(11);flag1=0;}shuchu(9);a=8;d=10*d+a;flag2=0;break;
case 0xbe:if(flag1){shuchu(11);flag1=0;}shuchu(10);a=9;d=10*d+a;flag2=0;break;
case 0x7e:if(!flag2){shuchu(11);b=flag;gongneng(flag,d);flag=1;flag2=1;d=0;}break;
case 0xed:if(flag1){shuchu(11);flag1=0;}shuchu(5);a=4;d=10*d+a;flag2=0;break;
case 0xdd:if(flag1){shuchu(11);flag1=0;}shuchu(6);a=5;d=10*d+a;flag2=0;break;
case 0xbd:if(flag1){shuchu(11);flag1=0;}shuchu(7);a=6;d=10*d+a;flag2=0;break;
case 0x7d:if(!flag2){shuchu(14);b=flag;gongneng(flag,d);flag=2;flag2=1;d=0;}break;
case 0xeb:if(flag1){shuchu(11);flag1=0;}shuchu(2);a=1;d=10*d+a;flag2=0;break;
case 0xdb:if(flag1){shuchu(11);flag1=0;}shuchu(3);a=2;d=10*d+a;flag2=0;break;
case 0xbb:if(flag1){shuchu(11);flag1=0;}shuchu(4);a=3;d=10*d+a;flag2=0;break;
case 0x7b:if(!flag2){shuchu(12);b=flag;gongneng(flag,d);flag=3;flag2=1;d=0;}break;
case 0xe7:if(!flag1){c--;shuchu(16);c--;if(d==0){d=f[--j];flag2=0;flag=b;}else{d=(d-a)/10;}}break;
case 0xd7:if(flag1){shuchu(11);flag1=0;}shuchu(1);a=0;d=10*d+a;flag2=0;break;
case 0xb7:shuchu(15);gongneng(flag,d);d=0;flag=0;
for(j=0;j<10;j++){jg=jg+f[j];}shuchu1(jg);
for(j=0;j<10;j++){f[j]=0;}
f[0]=jg;
d=0;
jg=0;
flag=0;
flag1=1;j=1;
break;
case 0x77:if(!flag2){shuchu(13);b=flag;gongneng(flag,d);flag=4;flag2=1;}
break;
}
}
void main()
{
uchar sta[]={"Write By "};
init();
write_cmd(0x01);
write_zfc(0,0,&sta[0]);
write_cmd(0x08);
init();
while (1)
{
jianpan0();
jianpan();
}
}