资源描述:
《基于51单片机的简易计算器.doc》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、基于51单片机的简易计算器/****************************************************************阿斌独家制作:计算器数码管显示可计算10以下数加减乘除可连续运算最大显示结果数值9999*****************************************************************/键盘设置:主程序:#include#defineuintunsignedint#defineucharunsignedcharucharnum,temp,jia=0,jian=0,cheng=0,chu
2、=0,qing=0;uintkey,key1;uchartable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x0};voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voidkeyscan(){P3=0xfe;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){case0xee:ke
3、y=1;num=0;break;case0xde:key=2;num=0;break;case0xbe:key=3;num=0;break;case0x7e:num=1;break;//加号}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xfd;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){case0xed:key=4;num=0;break;case0xdd:ke
4、y=5;num=0;break;case0xbd:key=6;num=0;break;case0x7d:num=2;break;//减号}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xfb;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){case0xeb:key=7;num=0;break;case0xdb:key=8;num=0;break;case0xbb:ke
5、y=9;num=0;break;case0x7b:num=3;break;//乘号}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xf7;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){case0xe7:key=0;num=0;break;case0xd7:num=6;break;//清除case0xb7:num=5;break;//等于号case0x77:num=4
6、;break;//除号}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}}voiddisplay(uintshu){uintqian,bai,shi,ge;qian=shu/1000;bai=shu%1000/100;shi=shu%100/10;ge=shu%10;P2=0x1f;if(qian==0)P0=table[10];elseP0=table[qian];delay(5);P2=0x2f;if(qian==0&&bai==0)P0=table[10];elseP0=table[bai];delay(5);P2=0x4f;if(qian==
7、0&&bai==0&&shi==0)P0=table[10];elseP0=table[shi];delay(5);P2=0x8f;P0=table[ge];delay(5);}voidjia1(){jia=1;jian=cheng=chu=qing=0;key1=key;}voidjian1(){jian=1;jia=cheng=chu=qing=0;key1=key;}voidcheng1(){cheng=1;jia