基于51單片機1602液晶顯示簡易計算器設(shè)計_第1頁
基于51單片機1602液晶顯示簡易計算器設(shè)計_第2頁
基于51單片機1602液晶顯示簡易計算器設(shè)計_第3頁
基于51單片機1602液晶顯示簡易計算器設(shè)計_第4頁
基于51單片機1602液晶顯示簡易計算器設(shè)計_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、R2'TRTLCEd3 .<T&T-灼U1WXTMIOWXT.U2P2TM,%二的層STMTPSC3::4-幵 / AC6":A IAN» <JL» d f j r * 9 ffxrm »zvx» rzn*n rSXKH »ZU*M rsAxn rz«Ai« V21iAtSfXDHM>M.V1X&rxairnfixvnxvnj»2crriF3“Tnew灼#include<reg52 h>#includemath h>#define uint un

2、signed int#define uchar unsigned chardefine PI 3. 141592sbit RS 二 P2P;sbit RW 二 P2°l;sbit EN 二 P22;sbit led=P24;sbit speek=P3*7;uchar tableO.j = ''Welcome to use" uchar tablelrj = /zmade by Ms. Li" uchar table2Lj = /zerrorz,;uchar count;void main(void)uchar error=0, i, first=0

3、, dotl, dot2, dotl_num, dot2_num, minusl, minus2;/錯 誤 標(biāo) 志、第一次淸屏標(biāo)志、小數(shù)點標(biāo)志以及小數(shù)點個數(shù)負(fù)號標(biāo)志、負(fù)號個數(shù)uchar Sin, Cos, Tan, In;uchar Key_num, ast_key_num;/鍵號uchar flag=0, equal_flag;運算符、等于符double numlO, num2=0, numO, result=0, save_result;/第一個數(shù)、第二個數(shù)、計算結(jié)果uchar first_num二0, Ans二0, second_num=0;InitLcdO ;EA二 1;ETO二1;T

4、MOD二0X01;THO=(65536-500)/256;TLO=(65536-500)%256;write_com(0x80+0x40+15); write_Dat (' O');write_com(0x80);while(l)while(key_scan0 =0xff);TRO=1;if(first=0)first=l; write_com(0x01);Key_num=key_scan 0;switch(key_scan 0)case 1:if (last_key_num! =Key_num) uTite_Dat C 1); uTite_Dat C n); ln=l;bre

5、ak;case 2:if (last_key_num! =Key_num) write_Dat (' s'); write_Dat (' i); write_Dat (' n ); Sin=l;break;case 3:if (last_key_num! =Key_num) write_Dat (' c ); write_Dat (' o'); write_Dat (' s'); Cos=l;break;case 4:if (last_key_num! =Key_num)write_Dat (' t ); writ

6、e_Dat (' a ); write_Dat (' n );Tan=l;break;case 5:if (last_key_num! =Key_num)writjDat (' r );flag=5;break;case 6:write_Dat(' 7');num=7;break; case 7:write_Dat C 8');num二8;break; case 8:write_Dat (' 9*) inum;break; case 9:if (last_key_num!二 Key_num)write_Dat (' +')

7、;flag=l;break;case 10:if(last_key_num!=Key_num)write_Dat (' T );flag=6;break;case 11:write_Dat C 4):num=4;break; case 12:write_Dat C o ) intimS;break; case 13:write_Dat(' 6');num二6;break; case 14:if(last_key_num!=Key_num)write_Dat (' -');flag二2;break;case 15:if(last_key_num!=Key_

8、num)if(equal_flag=l) write_com(0x01); write_com(0x80); write_Dat (' A'); write_Dat (' n'); write_Dat (' s'); write_Dat ('='); save_result=result;else if(Key_num!=l&&Key_num!=2&&Key_num!=3&&Key_num!=4&&Key_num!=22&&Key_num!=23 &a

9、mp;&Key_num!二25)write_Dat(' A') ;write_Dat C n ) ;write_Dat (' s'); if(flag=O)numl=save_result; first_num=l;elsenum2=save_re sult; second_num=l;break;case 16:write_Dat(* V):num=l;break;case 17:write_Dat(' 2):num=2;break;case 18:write_Dat(* 3):num=3;break;case 19:if(last_key_n

10、um!=Key_num)write_Ddt (' *'); flag=3;break;case 21:write_Dat (' O') ;num二0;break;case 22:if (last_key_num! =Key_num)辻(flag=O) minusl+; if(minusl=l)writjDat (' -');elseminus2+;if(minus2=l)uTite_Dat -'); break;case 23:if (last_key_num!=Key_num)if(flag=O)dotl+;if(dotl=l)writ

11、e_Dat(');elsedot2+;辻(dot2=l)uTite_Dat('); break;case 24:if (last_key_num! =Key_num)write_Dat (' /');flag二4;break;case 25:if (last_key_num! =Key_num) write_Dat ('='); equal_flag=l;break;if (Key_num! =l&&Key_num! =2&&Key_num! =3&&Key_num! =4&&Key

12、_num! =15&&Key_num !=22 &&Key_num 匸23&&Key_num!二 25)/第一個數(shù)if(flag=O)num1二num1*1O+num;num二0;if(dotl!=0)dotl_num+;first_num=l;if(flag!二0)num2=num2*l0+num;num=0;if(dot2!=0)dot2_num+;second_num=l;if (equal_f1ag=l&&f i r s t_num=1)if(dotl!=0)numl=numl/pow(10, dotl_num):dotl

13、=0;if(dot2!=0)num2=num2/pow(10, dot2_num);dot2=0;if(minusl!=0)numl=numl*(-l);if(minus2!=0) num2=num2*(-l);if(second_num!=0)switch(flag)case 1: resul t=numl+nuni2: break;case 2: result=numl-nuni2: break;case 3: result=numl*nuni2; break;case 4:if(num2!=0)result =num1/num2;elsewrit e_c om(0x80+0x40+10)

14、;for(i=0;i<5;i+)Tite_Dat(table2ij);error=l; break;case 5: resultpowCnuml, num2);break;case 6: resultpowCnuml, l/num2):break;else if (second_num二二0&&Sin=0&&Cos=0&&Tan=0&&ln=0) result=numl;else if (second_num=0&& (Sin=l Cos=l Tan=l ln=l) if(Sin=l)result=sin(n

15、uml/180*PI)+0. 005;if (Cos=l)result=cos(numl/180*PI)+0. 005;辻(Tan二二1)result=tan(numl/180*PI)+0.005;if(ln=l)if(numl>0)result=log(numl)+0. 005; elsewrite_com(0x80+0x40+10); for(i=0;i<5;i+)utite_Dat(table2i);error=l;if(error!=1)display(result);if(Key_num=20) /淸零numl=num2=result=0;flag=equal_flag=

16、O;error=0;first=0;dotl_num二dot2_num=0;minusl=0;minus2=0;first_num=0, second_num=0;Sin=Cos=Tan=ln=0; write_com(0x01);write_com(0x80+0x40+15); write_Dat (' O');las t_ke y_num=Ke y_num;while(key_scan()!=0xff);void timeOO interrupt 1THO=(65536-600)/256;TLO=(65536-600)%256;count+;speek=!speek;if(

17、count>50)TRO二0; count=0;void delay(uint x)uchar y;while(x) for (y=0;y<120;y+);void write_com(unsigned char c) RS 二0;RW二 0;EN=1;delay (5);P0二c;EN=0;void writeDat(unsigned char c) RS二 1;RW二 0;EN=1;delay (5);P0 二c;EN=0;void InitLcdOwrite_com(0x38); /display modewrite_com(0x06); /顯示光標(biāo)移動位置 write_co

18、m(0x0c); /顯示開及光標(biāo)設(shè)置 write_com(0x01); /顯示淸屏uchar key_scan()uchar key_num=0xff;uint temp;P3=0x03;Pl=OxeO; temp=(P3<<8) Pl; if(temp&0x03e0)!=0x03e0)delay (10);if(temp&0x03e0)!=0x03e0)P3=0x03;/第一行Pl=0xfe;temp=(P3«8) Pl;switch(temp)case 0x03de:key_num=l; break;case 0x03be:key_num=2; bre

19、ak;case OxO37e:key_num=3; break;case 0x02fe:key_num=4; break;case 0x01fe:key_num=5; break;P3=0x03:/第二行Pl=0xfd;temp=(P3<<8) Pl;switch(temp)case 0x03dd:keyumG; break;case 0x03bd:key_num=7; break;case OxO37d:key_num=8; break;case 0x02fd:key_num=9; break;case 0x01fd:key_num=10; break;P3=0x03;/第三行P

20、l=0xfb;temp=(P3<<8) Pl;break; break; break; break; break;switch(temp)case 0x03db:key_num=l1case 0x03bb:key_num=12case 0x037b:key_num=13case 0x02fb:key_num=14case 0x01fb:key_num=15 P3=0x03;/第四行Pl=0xf7;temp=(P3<<8) Pl; switch(temp)case0x03d7:key_num=16;break;case0x03b7:key_num=17;break;cas

21、e0x0377:key_num=18;break;case0x02f7:key_num=19;break;case0x01f7:key_num=20;break;jP3=0x03;Pl=0xef;/第五行temp=(P3«8) Pl; switch(temp)casecasecasecasecase0x03cf:key_num=21;0x03af:key_num=22;0x036f:key_num=23;0x02ef:key_num=24;0x0lef:key_num=25;break; break; break; break; break;returnkey_num;void di

22、splay(double Data) uchar xs=0, fs=0,i;if(Data<0)fs=l;Data=Data*(-1);if(Data>(long)Data)xs=l;0'9if(Data<10)if(xs=l)Data=Data*100; write_ (0x80+0x40+11); 辻(fs=l) write_Dat(-);elsewrite_Dat ('');write_Dat(long)Data/100+* 0*);writeDat (');write_Dat(long)Data/10%10+,0);write_Dat(

23、long)Data弔10+' 0*);else if (xs=0)write_com(0x80+0x40+14);if(fs=l)writeDat (' -');elsewrite_Dat ('');write_Dat(long)Data+,0,);else 辻(Data<100)/10、99if (xs=l)Data=Data*100;write_com(0x80+0x40+10);if(fs=l)write_Datelsewrite_Dat ('');write_Dat(long)Data/1000+,O');write

24、_Dat(long)Data/100%10+,0);write_Dat (');write_Dat(long)Data/10%10+,O'); writeDat(long)Data%10+* 0);else if (xs=0)write_com(0x80+0x40+13);if(fs=l)write_Datelsewrite_Dat ('');write_Dat (long)Data/10+* 0);write_Dat (long)Data%10+* O');else if (Data<1000)/100999辻(xs=l)Data=Data*10

25、0;write_com(0x80+0x40+9);if(fs=l)write_Datelsewrite_Dat ('');writjDat (long)Data/10000+' O'); write_Dat(long)Data/1000%10 +'O'); write_Dat(long)Data/100%10+,O');write_Dat (');write_Dat(long)Data/10%10+,O');write_Dat(long)Data%10+* 0*);else if (xs=0)write_com(0x80+

26、0x40+12); if(fs=l)write_Datelsewrite_Dat ('');write_Dat(1ong)Data/100+,O'); write_Dat(1ong)Data/10%10+,O');write_Dat(long)Data%10+* O');else 辻(Data<10000)7/10009999if (xs=l)Data=Data*100;wr ite_com(0x80+0x40+8);if(fs=l)writeDatelsewrite_Dat ('');write_Dat (long)Data/10

27、0000+,O');writeDat(long)Data/10000%10+,O');write_Dat(long)Data/1000%10 +'O');write_Dat(long)Data/100%10+,0*);write_Dat (');write_Dat(long)Data/10%10+,O');write_Dat(long)Data%10+* 0,);else if (xs=0)write_com(0x80+0x40+11);if(fs=l)write_Datelsewrite_Dat ('');write.Dat(l

28、ong)Data/1000+,CT ); write.Dat(long)Data/100%10+,0*);write.Dat (long)Data/10%10+,O');write_Dat(long)Data%10+,0);else 辻(Data<100000)/10000、99999if (xsl)Data=Data*100;wr i te_com(0x80+0x40+7);if(fs=l)write_Datelsewrite_Dat ('');writeDat(long)Data/1000000> 0); write_Dat(long)Data/1000

29、00%10+,0*); write_Dat(long)Data/10000%10+' O');write_Dat(long)Data/1000%10 +'0);write.Dat (long)Data/100%10+,O');write_Dat (');write_Dat (long)Data/10%10+,0*); write_Dat(long)Data%10+* 0*);else if(xs=0)write_com(0x80+0x40+10);if(fs=l)write_Dat (');elsewrite_Dat ('');write_Dat(long)Data/10000+* O'); write.Dat (long)Data/1000%10+>O'); write_Dat(long)Data/100%10+,O'); write_Dat(long)Data/10%10+,O

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論