基于单片机的简易计算器设计原理图及程序代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
P2=0xff;
}
}
ET0=1;
}
{
do
{
dsp[0]=keyscan();
if(dsp[0]==14||dsp[0]<10)
{
BEEP=1;
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
c=0;
}
}while((dsp[0]==15)&&(c==0));
}
else if(dsp[0]==14)
{
BEEP=1;
if(k==10)
{
x=x+y;
if(x>99999999)
{
BEEP=0;
r[0]=11;
r[1]=11;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
for(i=7;i>0;i--)
{
if(r[i]==0)
r[i]=12;
else
break;
}
for(i=0;i<8;i++)
{wenku.baidu.com
dsp[i+1]=r[i];
}
}
void main(void)
{
char i,j,k,c;
}
}
void calculate(char k,char a[8],char b[8])
{
char r[8];
long i;
long x,y;
i=0;
x=0;
y=0;
for(i=7;i>0;i--)
{
while(a[i]==12)a[i]=0;
while(b[i]==12)b[i]=0;
}
x=a[4];
case 0xbd:{return 5;break;}
case 0xdd:{return 6;break;}
case 0x7b:{return 7;break;}
case 0xbb:{return 8;break;}
case 0xdb:{return 9;break;}
case 0xee:{return 10;break;}//加法
switch(KeyL | KeyR)
{
case 0xb7:{return 0;break;}
case 0x7e:{return 1;break;}
case 0xbe:{return 2;break;}
case 0xde:{return 3;break;}
case 0x7d:{return 4;break;}
{0xc0,0xf9,0xa4,0xb0,0x99,//0-4
0x92,0x82,0xf8,0x80,0x90,//5-9
0x86,0xaf,0xff,0x7f,0xbf};//E,r,不显,.,-
void delay11(unsigned int i)
{
while(i--);
}
char keyscan()
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
if(k==13)
{
if(y==0)
{
BEEP=0;
r[0]=11;
r[1]=11;
{
x=0;
}
else if(x>99999999||x<i)
{
BEEP=0;
r[0]=11;
r[1]=11;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
{
char KeyL;
char KeyR;
P1=0xf0;
do
{
do
{
P1=0xF0;
P1=P1|0xF0;
if(P1!=0xF0)
{
KeyL=P1;
P1=0x0F;
P1=P1|0x0F;
KeyR=P1;
}
}while(KeyL==0xF0||KeyR==0x0F);
delay11(300);
}while(P1!=0x0F);
原理图:
#include<reg52.H>
sbit BEEP=P3^7;
char dsp[9]={0,0,12,12,12,12,12,12,12};
unsigned char code Select[]=
{0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code LED_CODES[]=
{
b[i]=dsp[i+1];
}
c=2;
if(dsp[0]!=15)
{
calculate(k,a,b);
for(i=0;i<8;i++)
{
a[i]=dsp[i+1];
}
k=dsp[0];
c=1;
goto KSC;
}
}
}while((dsp[0]==15)&&(c<2));
calculate(k,a,b);
r[0]=11;
r[1]=11;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
x=x/y;
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
c=0;
}
while(dsp[0]==15&&c==0)
{
dsp[0]=keyscan();
if(dsp[0]==14||dsp[0]<10)
{
dsp[0]=14;
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
if(k==11)
{
if(x<y)
{
x=y-x;
if(x>9999999)
{
BEEP=0;
r[2]=(x%1000)/100;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
if(k==12)
{
i=x;
x=x*y;
if(y==0)
case 0xed:{return 11;break;}//减法
case 0xeb:{return 12;break;}//乘法
case 0xe7:{return 13;break;}//除法
case 0xd7:{return 14;break;}//清零
case 0x77:{return 15;break;}//等于
goto KSC;
while(1);
}
void display() interrupt 1
{
char i,j,h;
ET0=0;
for(j=8;j>0;j--)
{
for(i=7;i>=0;i--)
{
P2=0xff;
P0=LED_CODES[dsp[8-i]];
P2=Select[i];
for(h=0;h<8;h++);
c=0;
}
else if(c==2&&dsp[0]>9)
{
c=0;
}
if(dsp[0]==0&&dsp[1]==0&&dsp[2]==12)
{
goto KSC;
}
else if(dsp[0]>9) break;
else
{for(j=i;j>0;j--)
dsp[j]=dsp[j-1];
}
}
if(i==9)
c=0;
}
}
}while(dsp[0]==14);
do
{
if(c==0)
{
k=dsp[0];
for(i=0;i<8;i++)
{
a[i]=dsp[i+1];
}
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
c=1;
goto KSC;
}
else if(c==1)
{
for(i=0;i<8;i++)
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
for(i=7;i>0;i--)
{
if(r[i]==0&&r[i-1]!=0)
{
r[i]=14;
break;
}
}
}
}
else
{
x=x-y;
r[0]=x%10;
r[1]=(x%100)/10;
char a[8],b[8];
TL0=0x00;
TH0=0x00;
EA = 1;
ET0 = 1;
TR0 = 1;
KSC:do
{
for(i=1;i<9;i++)
{
dsp[0]=keyscan();
if(c==2&&dsp[0]<10)
{
dsp[1]=dsp[0];
for(j=2;j<9;j++)
dsp[j]=12;
x=10000*x;
x=x+a[0]+a[1]*10+a[2]*100+a[3]*1000+a[5]*100000+a[6]*1000000+a[7]*10000000;
y=b[4];
y=10000*y;
y=y+b[0]+b[1]*10+b[2]*100+b[3]*1000+b[5]*100000+b[6]*1000000+b[7]*10000000;
}
}
ET0=1;
}
{
do
{
dsp[0]=keyscan();
if(dsp[0]==14||dsp[0]<10)
{
BEEP=1;
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
c=0;
}
}while((dsp[0]==15)&&(c==0));
}
else if(dsp[0]==14)
{
BEEP=1;
if(k==10)
{
x=x+y;
if(x>99999999)
{
BEEP=0;
r[0]=11;
r[1]=11;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
for(i=7;i>0;i--)
{
if(r[i]==0)
r[i]=12;
else
break;
}
for(i=0;i<8;i++)
{wenku.baidu.com
dsp[i+1]=r[i];
}
}
void main(void)
{
char i,j,k,c;
}
}
void calculate(char k,char a[8],char b[8])
{
char r[8];
long i;
long x,y;
i=0;
x=0;
y=0;
for(i=7;i>0;i--)
{
while(a[i]==12)a[i]=0;
while(b[i]==12)b[i]=0;
}
x=a[4];
case 0xbd:{return 5;break;}
case 0xdd:{return 6;break;}
case 0x7b:{return 7;break;}
case 0xbb:{return 8;break;}
case 0xdb:{return 9;break;}
case 0xee:{return 10;break;}//加法
switch(KeyL | KeyR)
{
case 0xb7:{return 0;break;}
case 0x7e:{return 1;break;}
case 0xbe:{return 2;break;}
case 0xde:{return 3;break;}
case 0x7d:{return 4;break;}
{0xc0,0xf9,0xa4,0xb0,0x99,//0-4
0x92,0x82,0xf8,0x80,0x90,//5-9
0x86,0xaf,0xff,0x7f,0xbf};//E,r,不显,.,-
void delay11(unsigned int i)
{
while(i--);
}
char keyscan()
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
if(k==13)
{
if(y==0)
{
BEEP=0;
r[0]=11;
r[1]=11;
{
x=0;
}
else if(x>99999999||x<i)
{
BEEP=0;
r[0]=11;
r[1]=11;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
{
char KeyL;
char KeyR;
P1=0xf0;
do
{
do
{
P1=0xF0;
P1=P1|0xF0;
if(P1!=0xF0)
{
KeyL=P1;
P1=0x0F;
P1=P1|0x0F;
KeyR=P1;
}
}while(KeyL==0xF0||KeyR==0x0F);
delay11(300);
}while(P1!=0x0F);
原理图:
#include<reg52.H>
sbit BEEP=P3^7;
char dsp[9]={0,0,12,12,12,12,12,12,12};
unsigned char code Select[]=
{0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code LED_CODES[]=
{
b[i]=dsp[i+1];
}
c=2;
if(dsp[0]!=15)
{
calculate(k,a,b);
for(i=0;i<8;i++)
{
a[i]=dsp[i+1];
}
k=dsp[0];
c=1;
goto KSC;
}
}
}while((dsp[0]==15)&&(c<2));
calculate(k,a,b);
r[0]=11;
r[1]=11;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[2]=10;
r[3]=12;
r[4]=12;
r[5]=12;
r[6]=12;
r[7]=12;
}
else
{
x=x/y;
r[0]=x%10;
r[1]=(x%100)/10;
r[2]=(x%1000)/100;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
c=0;
}
while(dsp[0]==15&&c==0)
{
dsp[0]=keyscan();
if(dsp[0]==14||dsp[0]<10)
{
dsp[0]=14;
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
if(k==11)
{
if(x<y)
{
x=y-x;
if(x>9999999)
{
BEEP=0;
r[2]=(x%1000)/100;
r[3]=(x%10000)/1000;
r[4]=(x%100000)/10000;
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
}
}
if(k==12)
{
i=x;
x=x*y;
if(y==0)
case 0xed:{return 11;break;}//减法
case 0xeb:{return 12;break;}//乘法
case 0xe7:{return 13;break;}//除法
case 0xd7:{return 14;break;}//清零
case 0x77:{return 15;break;}//等于
goto KSC;
while(1);
}
void display() interrupt 1
{
char i,j,h;
ET0=0;
for(j=8;j>0;j--)
{
for(i=7;i>=0;i--)
{
P2=0xff;
P0=LED_CODES[dsp[8-i]];
P2=Select[i];
for(h=0;h<8;h++);
c=0;
}
else if(c==2&&dsp[0]>9)
{
c=0;
}
if(dsp[0]==0&&dsp[1]==0&&dsp[2]==12)
{
goto KSC;
}
else if(dsp[0]>9) break;
else
{for(j=i;j>0;j--)
dsp[j]=dsp[j-1];
}
}
if(i==9)
c=0;
}
}
}while(dsp[0]==14);
do
{
if(c==0)
{
k=dsp[0];
for(i=0;i<8;i++)
{
a[i]=dsp[i+1];
}
dsp[1]=0;
for(i=2;i<9;i++)
dsp[i]=12;
c=1;
goto KSC;
}
else if(c==1)
{
for(i=0;i<8;i++)
r[5]=(x%1000000)/100000;
r[6]=(x%10000000)/1000000;
r[7]=x/10000000;
for(i=7;i>0;i--)
{
if(r[i]==0&&r[i-1]!=0)
{
r[i]=14;
break;
}
}
}
}
else
{
x=x-y;
r[0]=x%10;
r[1]=(x%100)/10;
char a[8],b[8];
TL0=0x00;
TH0=0x00;
EA = 1;
ET0 = 1;
TR0 = 1;
KSC:do
{
for(i=1;i<9;i++)
{
dsp[0]=keyscan();
if(c==2&&dsp[0]<10)
{
dsp[1]=dsp[0];
for(j=2;j<9;j++)
dsp[j]=12;
x=10000*x;
x=x+a[0]+a[1]*10+a[2]*100+a[3]*1000+a[5]*100000+a[6]*1000000+a[7]*10000000;
y=b[4];
y=10000*y;
y=y+b[0]+b[1]*10+b[2]*100+b[3]*1000+b[5]*100000+b[6]*1000000+b[7]*10000000;