计算器程序完美版单片机

上传人:M****1 文档编号:467407208 上传时间:2023-01-13 格式:DOC 页数:11 大小:30.01KB
返回 下载 相关 举报
计算器程序完美版单片机_第1页
第1页 / 共11页
计算器程序完美版单片机_第2页
第2页 / 共11页
计算器程序完美版单片机_第3页
第3页 / 共11页
计算器程序完美版单片机_第4页
第4页 / 共11页
计算器程序完美版单片机_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《计算器程序完美版单片机》由会员分享,可在线阅读,更多相关《计算器程序完美版单片机(11页珍藏版)》请在金锄头文库上搜索。

1、#include#include#define uint unsigned int#define uchar unsigned charsbit dula=P26;sbit wela=P27;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0;uchar sign=0;char ifnum=0,ifcount=0,dian=0,dian1=0;long len=10;float result=0,b=0,key;void delay(uint z);

2、uchar keyscan();void display(long aa);void yunsuan();char table18=0x00,0x00,0x00,0x00,0x00,0x3f;void main()int i;dula=1;P0=0;dula=0;wela=1;P0=0xff;wela=0;/display(0);/delay(3000);while(1)char h=0xfe,k,j=0;for(k=6;k0;k-)dula=1;P0=table1j+;dula=0;P0=0xff;wela=1;P0=h;h=(h=1&key=1&key=10)/在0到9之间,证明按下的是数

3、值if(result=11&key=14)/在11到1之间,证明按下的是符号if(ifcount=1)sign=key;/标记为1 ,已显示结果,只改变运算符else if(sign=0&ifnum=0);/之前无按键else if(sign=0&ifnum=1)/之前只按过数字键sign=key;b=result;result=0;else if(sign!=0&ifnum=0)/之前按过数字键和符号键sign=key;else/之前按过数字键和符号键及数字键yunsuan();sign=key;b=result;result=b;ifnum=0;dian1=0;len=10;elseif(

4、key=15&dian1=0)/按下小数点键dian=1;dian1=1;len=10;elseif(key=16)/按下等于键if(ifcount=0)if(sign!=0&ifnum=1)yunsuan();b=result;result=b;sign=0;ifnum=0;dian1=0;len=10;for(i=0;i2000;i+);result=result*100;display(result);key=keyscan();void yunsuan()switch(sign) case 11:result=b+result;result=result*100;display(res

5、ult);break; case 12:result=b-result;result=result*100;display(result);break;case 13:result=b*result;result=result*100;display(result);break;case 14:result=b/result;result=result*100;display(result);break;default:break;ifcount=1;uchar keyscan()uchar num=0,temp;P3=0x01;temp=P3;temp=temp|0x0f;while(tem

6、p!=0x0f)/判断是否有键按下delay(3);temp=P3;temp=temp|0x0f;while(temp!=0x0f)/确认是否有键按下temp=P3;switch(temp)case 0x11:num=1;break;case 0x21:num=2;break;case 0x41:num=3;break;case 0x81:num=4;break;while(temp!=0x0f)/松手检测temp=P3;temp=temp|0x0f;P3=0xfd;temp=P3;temp=temp&0xf0;while(temp!=0xf0)delay(3);temp=P3;temp=te

7、mp&0xf0;while(temp!=0xf0)temp=P3;switch(temp)case 0xed:num=5;break;case 0xdd:num=6;break;case 0xbd:num=7;break;case 0x7d:num=8;break;while(temp!=0xf0)temp=P3;temp=temp&0xf0;P3=0xfb;temp=P3;temp=temp&0xf0;while(temp!=0xf0)delay(3);temp=P3;temp=temp&0xf0;while(temp!=0xf0)temp=P3;switch(temp)case 0xeb:

8、num=9;break;case 0xdb:num=10;break;case 0xbb:num=11;break;case 0x7b:num=12;break;while(temp!=0xf0)temp=P3;temp=temp&0xf0;P3=0xf7;temp=P3;temp=temp&0xf0;while(temp!=0xf0)delay(3);temp=P3;temp=temp&0xf0;while(temp!=0xf0)temp=P3;switch(temp)case 0xe7:num=13;break;case 0xd7:num=14;break;case 0xb7:num=15

9、;/为什么num一清零,读书就显示为0break;case 0x77:num=16;/发现一个问题,显示的读数不是a,而是numbreak;while(temp!=0xf0)temp=P3;temp=temp&0xf0;return(num);void display(long aa)char r=0xdf;long k=aa,e=0,e1=2;if(aa/100)!=(result/100)|dian1=1)/判断是否有小数点dian=1;elsedian=0;wela=1;P0=0xff;wela=0;if(k=0)char n;dula=1;P0=0x00;dula=0;r=0xdf;if(k=0)if(len=100)dula=1;P0=table0;dula=0;P0=0xff;wela=1;P0=r;wela=0;delay(8);r=(r1)|0x80;dula=1;if(dian!=0)P0=table0|0x80;elseP0=table0;dula=0;P0=0xff;wela=1;P0=r;wel

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 试题/考题 > 初中试题/考题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号