简单计算器源程序
时间:08-15
来源:互联网
点击:
#includereg51.h>#includemath.h>#define uint unsigned int#define uchar unsigned charuchar code tab[]={0xee,0xed,0xeb,0xe7,0xde,0xdd,0xdb,0xd7,0xbe,0xbd,0xbb,0xb7,0x7e,0x7d,0x7b,0x77,}; //0~f键位码表uchar code tab1[]={0x88,0Xbe,0Xc4,0X94,0Xb2,0X91,0X81,0Xbc,0X80,0X90,0xa0,0x83,0xc9,0x86,0xc1,0xe1,0xff}; //0~f字型码表void delay(uchar x) //毫秒级延时函数{uchar y; for(;x>0;x--)for(y=110;y>0;y--);}scanf() //按键处理函数 {uchar temp,temp1,i; P0=0xf0; //给P0口赋值为oxf0,用于列扫描if(P0!=0xf0) //判别是否有键按下{delay(2); if(P0!=0xf0) //再次判别是否有键按下{temp1=P0; //P0值赋给temp1P0=0x0f; //P0值赋为0x0f,用于行扫描temp=temp1|P0; //将行列扫描值合并,赋给temp}switch(temp){case 0xee:i=1; break;case 0xed:i=2; break;case 0xeb:i=3; break;case 0xe7:i=4; break;case 0xde:i=5; break;case 0xdd:i=6; break;case 0xdb:i=7; break;case 0xd7:i=8; break;case 0xbe:i=9; break;case 0xbd:i=0; break;case 0xbb:i=10; break;case 0xb7:i=11; break;case 0x7e:i=12; break;case 0x7d:i=13; break;case 0x7b:i=14; break;case 0x77:i=15; break; }}else return 16;return i;} void display(uint temp) //显示函数{uchar i;uchar z[6];z[0]=16;z[1]=temp/10000;z[2]=temp%10000/1000;z[3]=temp%1000/100;z[4]=temp%100/10;z[5]=temp%10;for(i=0;i6;i++){ SBUF=tab1[z[i]]; // 根据键位值找到键码值,将键码值赋给串行口发送寄存器while(!TI); //判断串口数据发送是否完毕TI=0; //串口数据发送完毕标志清0}}E(uchar n){uint t=1;for(;n>0;n--)t=t*10;return t; }void main(void) //主函数{ uint tem,tem1;uchar x,y,fh,j,k=0;uchar zhi[6];uchar zhi1[6];while(1){if(x5!k){ if(scanf()10){delay(5);if(scanf()10){if(x==0){zhi[0]=scanf();while(scanf()!=16);}if(x==1){zhi[1]=scanf();while(scanf()!=16);}if(x==2){zhi[2]=scanf();while(scanf()!=16);}if(x==3){zhi[3]=scanf();while(scanf()!=16);}if(x==4){zhi[4]=scanf();while(scanf()!=16);} x++; tem=0;for(y=0;yx;y++){ tem=tem+zhi[y]*E(x-1-y);}display(tem);}}}if(scanf()>11scanf()16){delay(2);if(scanf()>9scanf()16){fh=scanf();while(scanf()!=16);k=1;}}if(j5k){ if(scanf()10){delay(2);if(scanf()10){if(j==0){zhi1[0]=scanf();while(scanf()!=16);}if(j==1){zhi1[1]=scanf();while(scanf()!=16);}if(j==2){zhi1[2]=scanf();while(scanf()!=16);}if(j==3){zhi1[3]=scanf();while(scanf()!=16);}if(j==4){zhi1[4]=scanf();while(scanf()!=16);}j++; tem1=0;for(y=0;yj;y++){ tem1=tem1+zhi1[y]*E(j-1-y);}display(tem1);}}}if(scanf()==11){delay(2);if(scanf()==11){ while(scanf()==11);if(fh==12)tem=tem+tem1;if(fh==13)tem=tem-tem1;if(fh==14)tem=tem*tem1;if(fh==15)tem=tem/tem1;display(tem);j=0;}}}}
- 基于AT89C51单片机的十进制计算器系统设计(06-29)
- 基于51单片机的简易计算器1602显示(12-02)
- 51单片机100内的加减乘除计算器C语言程序(11-30)
- 16键计算器 c51实现(11-29)
- 基于单片机计算器的汇编程序(11-25)
- 基于51单片机的计算器 C语言程序(11-25)