资源描述:
《基于at89c51单片机c语言编写的计算器》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#defineuintunsignedint#defineucharunsignedcharsbitdula=P2^6;sbitwela=P2^7;sbitkey1=P3^4;ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0};ucharnum,temp,num1;voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}ucharkeyscan()
2、;voiddisplay(ucharaa);voidmain(){num=17;dula=1;P0=0;dula=0;wela=1;P0=0xc0;wela=0;while(1){display(keyscan());}}voiddisplay(ucharaa){dula=1;P0=table[aa-1];dula=0;}ucharkeyscan(){P3=0xfe;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){cas
3、e0xee:num=1;break;case0xde:num=2;break;case0xbe:num=3;break;case0x7e:num=4;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:num=5;break;case0xdd:num=6;break;case0xbd:num
4、=7;break;case0x7d:num=8;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:num=9;break;case0xdb:num=10;break;case0xbb:num=11;break;case0x7b:num=12;break;}while(temp!=0xf0)
5、{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:num=13;break;case0xd7:num=14;break;case0xb7:num=15;break;case0x77:num=16;break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}returnnum;}/89C51单片机
6、【计算器】C语言程序// P2位选P0段选时钟12MHZ /#include /包含的头文件/#defineucharunsignedchar /宏定义/#defineuintunsignedintucharLed[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f, 0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; /数码管段选/longfloatNumber[]={0,0,0,0}; /数码管显示位控制寄存器/ ucharA[]={0x00,0x00,0x00,0x
7、00,0x00,0x00,0x00,0x00};longintD[]={0,0,0,0,0,0,0,0}; //数码管显示内容寄存器 ucharcodeC[]={0x0,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; /数码管位选/ /列扫描控制LED1位2位3位4位5位6位7位8位/uchark=16; / 按键对外控制 /uchar