计算器C语言程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
case 15:{ flag=1;fuhao=1;display(),b=0;};break;
{ display(); keyscan();
} } 仿真图:
仿真所选原件。
P3=0xfb; if(P3!=0xfb) {
delay(10); if(P3!=0xfb) {
temp=P3&0xf0; switch(temp) {
case 0xe0:num=8;break; case 0xd0:num=9;break; case 0xb0:num=10;break; case 0x70:num=11;break; } while(P3!=0xfb); if(num==8||num==9||num==10) { panduan(); } else { flag=1; fuhao=2,b=0; } } } P3=0xf7; if(P3!=0xf7) { delay(10); if(P3!=0xf7) { temp=P3&0xf0; switch(temp) { case 0xe0:num=12;break; case 0xd0:num=13;break; case 0xb0:num=14;break; case 0x70:num=15;break; } while(P3!=0xf7); switch(num) { case 12:;break;
if(a5!=table2[0]||a4!=table2[0]||a3!=table2[0]||a2!=table2[0]||a1!=table2[0]) {P2=0x00; P0=a1; P2=0X10; delay(1); }
P2=0x00; P0=a0; P2=0X20; delay(1); } void azy() { a5=a4; a4=a3; a3=a2; a2=a1; a1=a0; } void bzy() { b5=b4;
for(j=110;j>0;j--); } void display() { if(a5!=table2[0])
{P2=0x00; P0=a5; P2=0X01; delay(1);
}
if(a5!=table2[0]||a4!=table2[0]) {P2=0x00; P0=a4; P2=0X02; delay(1); }
if(a5!=table2[0]||a4!=table2[0]||a3!=table2[0]) {P2=0x00; P0=a3; P2=0X04; delay(1); }
if(a5!=table2[0]||a4!=table2[0]||a3!=table2[0]||a2!=table2[0]) {P2=0x00; P0=a2; P2=0X08; delay(1); }
flag=1; fuhao=4,b=0; } } } P3=0xfd;源自文库if(P3!=0xfd) { delay(10); if(P3!=0xfd) { temp=P3&0xf0; switch(temp) { case 0xe0:num=4;break; case 0xd0:num=5;break; case 0xb0:num=6;break; case 0x70:num=7;break; } while(P3!=0xfd); if(num==4||num==5||num==6) { panduan(); } else { flag=1; fuhao=3,b=0; } } }
a0=0xc0;b0=0xc0; a1=a2=a3=a4=a5=b1=b2=b3=b4=b5=0xff; flag=0,flaga=0,flagb=0;flagz=0; a=0,b=0,c=0; } void qn() { b0=b1=b2=b3=b4=b5=0xff; } uchar code table1[]={ 0xf8,0x80,0x90,0, 0x99,0x92,0x82,0, 0xf9,0xa4,0xb0,0, 0,0xc0,0,0}; uchar code table2[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uint code table[]={ 7,8,9,0, 4,5,6,0, 1,2,3,0, 0,0,0,0 }; void delay(uint xms) { uint i,j; for(i=xms;i>0;i--)
if(flaga==1) { if(a5==0xff)
{a=a*10+table[num]; azy(); a0=table1[num]; display(); } } else { a=table[num]; a0=table1[num]; display(); flaga=1; } } else {
b4=b3; b3=b2; b2=b1; b1=b0; } void fuzhi() { a5=b5; a4=b4; a3=b3; a2=b2; a1=b1; a0=b0; } void qh() { a0=table2[c%10]; a1=table2[(c/10)%10]; a2=table2[(c/100)%10]; a3=table2[(c/1000)%10]; a4=table2[(c/1000)%10]; a5=table2[(c/10000)%10]; } void panduan() { if(flag==0) {
数码管显示计算器 C 语言程序如下: #include <reg51.h> #include <math.h> #define uchar unsigned char #define uint unsigned int uchar i,j,temp,num; uchar a0,a1,a2,a3,a4,a5,b0,b1,b2,b3,b4,b5; uchar flag,flaga,flagb,fuhao; long a,b,c,flagz; void init() {
} } } } void main() { init(); while(1)
case 14:flagz=1; if(fuhao==1) { c=a+b;jieguo(); /*qh(); display(); qn();ag_eq();*/ } else if(fuhao==2) { if(a-b>=0) { c=a-b; qh(); display();ag_eq(); } else { c=b-a; qh(); display(); } qn();ag_eq(); } else if(fuhao==3) { c=a*b; qh(); display();qn();ag_eq(); } else if(fuhao==4) { c=a/b; qh(); display();qn();ag_eq(); } break;
if(flagb==1) { if(b5==0xff)
{b=b*10+table[num]; bzy(); b0=table1[num]; fuzhi(); display(); } } else { b=table[num]; b0=table1[num]; fuzhi(); display(); flagb=1; } } } void ag_eq()//再次按下等于时 { if(flagz==1) { a=c; } } void jieguo() { if(c<=1000000) {qh(); display();qn();ag_eq(); } else {a5=0x86;a0=a1=a2=a3=a4=0xff;display();} } void keyscan() { P3=0xfe; if(P3!=0xfe) { delay(10); if(P3!=0xfe) { temp=P3&0xf0; switch(temp)
case 13: if(flag==0) {
if(flaga==1) {
a=a*10+table[num]; azy(); a0=table1[num]; display(); } else { if(a==0) {display();} else {a0=table1[num]; a=a*10+table[num]; display(); flaga=1; } } } else { if(flagb==1) { b=b*10+table[num]; bzy(); b0=table1[num]; fuzhi(); display(); } else { if(b==0) {display();} else {b0=table1[num]; b=a*10+table[num]; fuzhi(); display(); flagb=1; } } } display(); break;
{ case 0xe0:num=0;break; case 0xd0:num=1;break; case 0xb0:num=2;break; case 0x70:num=3;break;
} while(P3!=0xfe); if(num==0||num==1||num==2) {
panduan(); } else {
{ display(); keyscan();
} } 仿真图:
仿真所选原件。
P3=0xfb; if(P3!=0xfb) {
delay(10); if(P3!=0xfb) {
temp=P3&0xf0; switch(temp) {
case 0xe0:num=8;break; case 0xd0:num=9;break; case 0xb0:num=10;break; case 0x70:num=11;break; } while(P3!=0xfb); if(num==8||num==9||num==10) { panduan(); } else { flag=1; fuhao=2,b=0; } } } P3=0xf7; if(P3!=0xf7) { delay(10); if(P3!=0xf7) { temp=P3&0xf0; switch(temp) { case 0xe0:num=12;break; case 0xd0:num=13;break; case 0xb0:num=14;break; case 0x70:num=15;break; } while(P3!=0xf7); switch(num) { case 12:;break;
if(a5!=table2[0]||a4!=table2[0]||a3!=table2[0]||a2!=table2[0]||a1!=table2[0]) {P2=0x00; P0=a1; P2=0X10; delay(1); }
P2=0x00; P0=a0; P2=0X20; delay(1); } void azy() { a5=a4; a4=a3; a3=a2; a2=a1; a1=a0; } void bzy() { b5=b4;
for(j=110;j>0;j--); } void display() { if(a5!=table2[0])
{P2=0x00; P0=a5; P2=0X01; delay(1);
}
if(a5!=table2[0]||a4!=table2[0]) {P2=0x00; P0=a4; P2=0X02; delay(1); }
if(a5!=table2[0]||a4!=table2[0]||a3!=table2[0]) {P2=0x00; P0=a3; P2=0X04; delay(1); }
if(a5!=table2[0]||a4!=table2[0]||a3!=table2[0]||a2!=table2[0]) {P2=0x00; P0=a2; P2=0X08; delay(1); }
flag=1; fuhao=4,b=0; } } } P3=0xfd;源自文库if(P3!=0xfd) { delay(10); if(P3!=0xfd) { temp=P3&0xf0; switch(temp) { case 0xe0:num=4;break; case 0xd0:num=5;break; case 0xb0:num=6;break; case 0x70:num=7;break; } while(P3!=0xfd); if(num==4||num==5||num==6) { panduan(); } else { flag=1; fuhao=3,b=0; } } }
a0=0xc0;b0=0xc0; a1=a2=a3=a4=a5=b1=b2=b3=b4=b5=0xff; flag=0,flaga=0,flagb=0;flagz=0; a=0,b=0,c=0; } void qn() { b0=b1=b2=b3=b4=b5=0xff; } uchar code table1[]={ 0xf8,0x80,0x90,0, 0x99,0x92,0x82,0, 0xf9,0xa4,0xb0,0, 0,0xc0,0,0}; uchar code table2[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uint code table[]={ 7,8,9,0, 4,5,6,0, 1,2,3,0, 0,0,0,0 }; void delay(uint xms) { uint i,j; for(i=xms;i>0;i--)
if(flaga==1) { if(a5==0xff)
{a=a*10+table[num]; azy(); a0=table1[num]; display(); } } else { a=table[num]; a0=table1[num]; display(); flaga=1; } } else {
b4=b3; b3=b2; b2=b1; b1=b0; } void fuzhi() { a5=b5; a4=b4; a3=b3; a2=b2; a1=b1; a0=b0; } void qh() { a0=table2[c%10]; a1=table2[(c/10)%10]; a2=table2[(c/100)%10]; a3=table2[(c/1000)%10]; a4=table2[(c/1000)%10]; a5=table2[(c/10000)%10]; } void panduan() { if(flag==0) {
数码管显示计算器 C 语言程序如下: #include <reg51.h> #include <math.h> #define uchar unsigned char #define uint unsigned int uchar i,j,temp,num; uchar a0,a1,a2,a3,a4,a5,b0,b1,b2,b3,b4,b5; uchar flag,flaga,flagb,fuhao; long a,b,c,flagz; void init() {
} } } } void main() { init(); while(1)
case 14:flagz=1; if(fuhao==1) { c=a+b;jieguo(); /*qh(); display(); qn();ag_eq();*/ } else if(fuhao==2) { if(a-b>=0) { c=a-b; qh(); display();ag_eq(); } else { c=b-a; qh(); display(); } qn();ag_eq(); } else if(fuhao==3) { c=a*b; qh(); display();qn();ag_eq(); } else if(fuhao==4) { c=a/b; qh(); display();qn();ag_eq(); } break;
if(flagb==1) { if(b5==0xff)
{b=b*10+table[num]; bzy(); b0=table1[num]; fuzhi(); display(); } } else { b=table[num]; b0=table1[num]; fuzhi(); display(); flagb=1; } } } void ag_eq()//再次按下等于时 { if(flagz==1) { a=c; } } void jieguo() { if(c<=1000000) {qh(); display();qn();ag_eq(); } else {a5=0x86;a0=a1=a2=a3=a4=0xff;display();} } void keyscan() { P3=0xfe; if(P3!=0xfe) { delay(10); if(P3!=0xfe) { temp=P3&0xf0; switch(temp)
case 13: if(flag==0) {
if(flaga==1) {
a=a*10+table[num]; azy(); a0=table1[num]; display(); } else { if(a==0) {display();} else {a0=table1[num]; a=a*10+table[num]; display(); flaga=1; } } } else { if(flagb==1) { b=b*10+table[num]; bzy(); b0=table1[num]; fuzhi(); display(); } else { if(b==0) {display();} else {b0=table1[num]; b=a*10+table[num]; fuzhi(); display(); flagb=1; } } } display(); break;
{ case 0xe0:num=0;break; case 0xd0:num=1;break; case 0xb0:num=2;break; case 0x70:num=3;break;
} while(P3!=0xfe); if(num==0||num==1||num==2) {
panduan(); } else {