资源描述:
《AT89C51单片机C语言编写计算器.doc》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
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--);}u
2、charkeyscan();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
3、){temp=P3;switch(temp){case0xee: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;
4、break;case0xdd:num=6;break;case0xbd:num=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:n
5、um=11;break;case0x7b:num=12;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:num=13;break;case0xd7:num=14;break;case0xb7:num=15;break;case0x77:num=16;break;
6、}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}returnnum;}/***************89C51单片机【计算器】C语言程序******************//**************** P2位选P0段选时钟12MHZ *********************/#include /*包含的头文件*/#defineucharunsignedchar /*宏定义*/#defineuintunsignedintucharLed[17]={0x3f,0x06,0x5b,0x4f,0x66
7、,0x6d,0x7d,0x07,0x7f, 0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; /*数码管段选*/longfloatNumber[]={0,0,0,0}; /*数码管显示位控制寄存器*/ ucharA[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};longintD[]={0,0,0,0,0,0,0,0}; //数码管显示内容寄存器 ucharcodeC[]={0x0,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,