資源描述:
《基于51單片機(jī)的計(jì)算器(附Proteus仿真圖且程序有詳細(xì)注釋).doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫。
1、#include#defineuintunsignedint#defineucharunsignedchar#definelintunsignedlongintucharSMG[10]={0x3f,0x06,0x5b,0x4f,//數(shù)碼管取模0x66,0x6d,0x7d,0x07,0x7f,0x6f};ucharDATA1[8]={0,0,0,0,0,0,0,0};//第一個(gè)數(shù)ucharDATA2[8]={0,0,0,0,0,0,0,0};//第二個(gè)數(shù)ucharRESUIT[8]={0,0,0,0,0,0,0,0};/
2、/結(jié)果ucharpx1=0,px2=0,px3=0,flag=0,flag1=0,flag2=0,flag3=0,f1=0,f2=0,f3=0,f4=0;//各全局變量uchartemp,key;lintx1=0,x2=0,y=0;//輸入的數(shù)及其結(jié)果voidInit();//系統(tǒng)初始化voidkeyscan();//鍵盤檢測(cè)voiddelay(uint);//延時(shí)voidDataOper();//數(shù)據(jù)運(yùn)算voidDataHandle();//數(shù)據(jù)接收voidDisplayHandle();//顯示處理voiddisplay(uchar
3、,uchar);//數(shù)碼管顯示函數(shù)voidmain(){P2=0x00;while(1){keyscan();DataHandle();DisplayHandle();}}voidInit()//初始化,所有數(shù)據(jù)歸零{uchari;px1=0;px2=0;px3=0;flag=0;flag1=0;flag2=0;flag3=0;f1=0;f2=0;f3=0;f4=0;x1=0;x2=0;y=0;for(i=0;i<8;i++){DATA1[i]=0;DATA2[i]=0;RESUIT[i]=0;}}voiddelay(msx)//msx
4、為延時(shí)毫秒數(shù){uinti,j;for(i=0;i<=msx;i++)for(j=0;j<=110;j++);}voiddisplay(ucharn,ucharm)//n是第幾只數(shù)碼管,m是顯示的數(shù)字是多少{switch(n){case0:P2=0xfe;break;case1:P2=0xfd;break;case2:P2=0xfb;break;case3:P2=0xf7;break;case4:P2=0xef;break;case5:P2=0xdf;break;case6:P2=0xbf;break;case7:P2=0x7f;brea
5、k;}P3=SMG[m];}voidkeyscan()//矩陣鍵盤掃描子函數(shù){P1=0xfe;temp=P1;temp=temp&0xf0;if(temp!=0xf0){delay(10);temp=P1;switch(temp){case0xee:key=0;flag=1;break;case0xde:key=1;flag=1;break;case0xbe:key=2;flag=1;break;case0x7e:key=3;flag=1;break;}while(temp!=0xf0){temp=P1;temp=temp&0xf0;}
6、}P1=0xfd;temp=P1;temp=temp&0xf0;if(temp!=0xf0){delay(10);temp=P1;switch(temp){case0xed:key=4;flag=1;break;case0xdd:key=5;flag=1;break;case0xbd:key=6;flag=1;break;case0x7d:key=7;flag=1;break;}while(temp!=0xf0){temp=P1;temp=temp&0xf0;}}P1=0xfb;temp=P1;temp=temp&0xf0;if(tem
7、p!=0xf0){delay(10);temp=P1;switch(temp){case0xeb:key=8;flag=1;break;case0xdb:key=9;flag=1;break;case0xbb:key=10;flag1=1;display(7,0);break;case0x7b:key=11;flag1=1;display(7,0);break;}while(temp!=0xf0){temp=P1;temp=temp&0xf0;}}P1=0xf7;temp=P1;temp=temp&0xf0;if(temp!=0xf0)
8、{delay(10);temp=P1;switch(temp){case0xe7:key=12;flag2=1;Init();break;case0xd7:key=13;flag2=1;DataOper()