新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 簡(jiǎn)單計(jì)算器源程序

簡(jiǎn)單計(jì)算器源程序

作者: 時(shí)間:2012-08-15 來源:網(wǎng)絡(luò) 收藏
#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~fuchar 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)          //毫秒級(jí)延時(shí)函數(shù){uchar y;           for(;x>0;x--)for(y=110;y>0;y--);}scanf()    //按鍵處理函數(shù)   {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)     //顯示函數(shù){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]];   // 根據(jù)鍵位值找到鍵碼值,將鍵碼值賦給串行口發(fā)送寄存器while(!TI);   //判斷串口數(shù)據(jù)發(fā)送是否完畢TI=0;         //串口數(shù)據(jù)發(fā)送完畢標(biāo)志清0}}E(uchar n){uint  t=1;for(;n>0;n--)t=t*10;return t; }void main(void)     //主函數(shù){ 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;}}}}


評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉