資源描述:
《基于51單片機(jī)的lcd1602液晶顯示的計(jì)算器.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
1、基于51單片機(jī)的lcd1602液晶顯示的計(jì)算器/****************************************************************阿斌獨(dú)家制作:計(jì)算器,1602液晶顯示可計(jì)算10以下數(shù)加減乘除可連續(xù)運(yùn)算,最大顯示結(jié)果數(shù)值65536*****************************************************************/鍵盤設(shè)置:液晶初始顯示:運(yùn)算顯示:主程序:#include#include
2、#defineuintunsignedint#defineucharunsignedcharsbitlcden=P2^2;sbitlcdrw=P2^1;sbitlcdrs=P2^0;ucharnum,temp,jia=0,jian=0,cheng=0,chu=0,qing=0;uintkey,key1,shu;ucharfuhao,flag1,flag=0;uchartable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
3、0x6f,0x0};voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}bitlcd_bz(){bitresult;lcdrs=0;lcdrw=1;lcden=1;_nop_();_nop_();_nop_();_nop_();result=(bit)(P0&0x80);lcden=0;returnresult;}voidwrite_com(ucharcom){while(lcd_bz());lcdrs=0;lcden=0;l
4、cdrw=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_date(uchardate){while(lcd_bz());lcdrs=1;lcden=0;lcdrw=0;P0=date;delay(5);lcden=1;delay(5);lcden=0;}voidlcd_init(){lcden=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);}void
5、keyscan(){P3=0xfe;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){case0xee:key=1;num=0;break;case0xde:key=2;num=0;break;case0xbe:key=3;num=0;break;case0x7e:num=1;break;//加號(hào)}while(temp!=0
6、xf0){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:key=4;num=0;break;case0xdd:key=5;num=0;break;case0xbd:key=6;num=0;break;case0x7d:num=2;bre
7、ak;//減號(hào)}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:key=7;num=0;break;case0xdb:key=8;num=0;break;case0xbb:key=9;num=0;bre
8、ak;case0x7b:num=3;break;//乘號(hào)}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:key=0;num=0;break;case0xd7:num=6;break;//清除case0