C51 LCD(LM044L)多功能可調(diào)時(shí)鐘設(shè)計(jì)_第1頁(yè)
C51 LCD(LM044L)多功能可調(diào)時(shí)鐘設(shè)計(jì)_第2頁(yè)
C51 LCD(LM044L)多功能可調(diào)時(shí)鐘設(shè)計(jì)_第3頁(yè)
C51 LCD(LM044L)多功能可調(diào)時(shí)鐘設(shè)計(jì)_第4頁(yè)
C51 LCD(LM044L)多功能可調(diào)時(shí)鐘設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、1、LCD(LM044L)多功能可調(diào)時(shí)鐘設(shè)計(jì)設(shè)計(jì)思路:利用單片機(jī)的定時(shí)器定時(shí),產(chǎn)生時(shí)鐘的時(shí)、分、秒,年、月、日,用LCD(LM044L)顯示出時(shí)間的時(shí)、分、秒,年、月、日,并用英文顯示“星期幾”具有百分之一秒,秒,分,跑表功能。一鍵開(kāi)始并記錄4組結(jié)果。使用若干個(gè)按鍵調(diào)整時(shí)間,一個(gè)用于選擇調(diào)整的時(shí)間位,一個(gè)用于調(diào)整時(shí)間。也可以使用多個(gè)鍵,用于調(diào)整各自的時(shí)間位。首先在proteus上繪制電路,編程模擬運(yùn)行實(shí)現(xiàn)。IiStViScS)詣?wù)a閭岸怕豐蠟町辛版出電碑|弓0丨篙宙丨=黑丨翳妙黑#|虧I靜誡I囤直/1國(guó)國(guó)1034甲州計(jì)汁嚴(yán)|HWFMC4C各譽(yù)Fsip55-5g/CFJmJeEMPU.足_3asP

2、SEx-iH&-3-mTfrMllE-snN*a.s3*frzla.tb.h&IWClaLpr_fri&FBRRfcssd*Jlc,Fzigmi-ir.運(yùn)行效果ZlBMWIEI丄TEEIJIIJI代碼#includevreg51.h包含單片機(jī)寄存器的頭文件#includevstdlib.h包含隨機(jī)函數(shù)rand()的定義文件#includevintrins.h包含_nop_()函數(shù)定義的頭文件sbitRS=P2A0;寄存器選擇位,將RS位定義為P2.0引腳sbitRW=P2A1;讀寫(xiě)選擇位,將RW位定義為P2.1引腳sbitE=P2A2;使能信號(hào)位,將E位定義為P2.2引腳sbitBF=P0A7

3、;忙碌標(biāo)志位,將BF位定義為P0.7引腳unsignedcharcodetable=2011-12-01;初始化液晶顯示10unsignedcharcodetable1=12:00:55;12unsignedcharcodetable2=week300:00:00;15unsignedcharcodetable3=00:00:0000:00:0000:00:0000:00:00;unsignedcharcount,s1num,s5num;charsecond,minute,hour,day,month,year,week;charms,sec,minu;sbits1=P1A0;功能鍵sbits

4、2=P1A1;加鍵sbits3=PM2;減鍵sbits4=PM3;保存并退出sbits5=P1A4;秒表voiddelay1ms()計(jì)算延遲1msunsignedchari,j;for(i=0;iv10;i+)for(j=0;jv33;j+)/*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*vt*1*1*1*/函數(shù)功能:延時(shí)若干毫秒入口參數(shù):n/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxT

5、xTxTxTxTxTxTxTxTxTxTxTx/voiddelay(unsignedcharn)unsignedchari;for(i=0;in;i+)delay1ms();/*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx

6、Tx函數(shù)功能:判斷液晶模塊的忙碌狀態(tài)返回值:result。result=l,忙碌;result=O,不忙/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx/unsignedcharBusyTest(void)bitresult;RS=O;根據(jù)規(guī)定,RS為低電平,RW為高電平時(shí),可以讀狀態(tài)RW=l;E=1;/E=1,才允許讀寫(xiě)_nop_();/空操作_nop_();_nop_();_nop_();/空操作四個(gè)機(jī)器周期,給硬件反應(yīng)時(shí)間resul

7、t=BF;/將忙碌標(biāo)志電平賦給resultE=0;/將E恢復(fù)低電平returnresult;/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx函數(shù)功能:寫(xiě)指令入口參數(shù):dictate*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*/TxTxTxTxTxTxTxTxTxTxTxT

8、xTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx/voidWriteInstruction(unsignedchardictate)while(BusyTest()=1);/如果忙就等待RS=0;RW=0;E=0;/根據(jù)規(guī)定,RS和R/W同時(shí)為低電平時(shí),可以寫(xiě)入指令/E置低電平(根據(jù)表8-6,寫(xiě)指令時(shí),E為高脈沖,/就是讓E從0到1發(fā)生正跳變,所以應(yīng)先置0_nop_();_nop_();P0=dictate;_nop_();_nop_();_nop_();_nop_();/空操作兩個(gè)機(jī)

9、器周期,給硬件反應(yīng)時(shí)間/將數(shù)據(jù)送入P0口,即寫(xiě)入指令或地址/空操作四個(gè)機(jī)器周期,給硬件反應(yīng)時(shí)間E=1;/E置高電平_nop_();_nop_();_nop_();_nop_();/空操作四個(gè)機(jī)器周期,給硬件反應(yīng)時(shí)間E=0;當(dāng)E由高電平跳變成低電平時(shí),液晶模塊開(kāi)始執(zhí)行命令/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx函數(shù)功能:寫(xiě)數(shù)據(jù)入口參數(shù):y(為字符常量)voidWriteData(unsignedchary)while(Bus

10、yTest()=1);RS=1;/RS為高電平,RW為低電平時(shí),可以寫(xiě)入數(shù)據(jù)RW=0;E=0;/E置低電平(根據(jù)表8-6,寫(xiě)指令時(shí),E為高脈沖,/就是讓E從0到1發(fā)生正跳變,所以應(yīng)先置0P0=y;/將數(shù)據(jù)送入P0口,即將數(shù)據(jù)寫(xiě)入液晶模塊_nop_();_nop_();_nop_();_nop_();/空操作四個(gè)機(jī)器周期,給硬件反應(yīng)時(shí)間E=1;/E置高電平_nop_();_nop_();_nop_();_nop_();/空操作四個(gè)機(jī)器周期,給硬件反應(yīng)時(shí)間E=0;當(dāng)E由高電平跳變成低電平時(shí),液晶模塊開(kāi)始執(zhí)行命令/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxT

11、xTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx函數(shù)功能:對(duì)LCD的顯示模式進(jìn)行初始化設(shè)置*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx/voidLcdln

12、itiate(void)unsignedcharnum;second=55;minute=0;hour=12;week=3;day=1;month=12;year=11;count=0;s1num=0;s5num=0;ms=0;sec=0;minu=0;E=0;delay(15);延時(shí)15ms,首次寫(xiě)指令時(shí)應(yīng)給LCD段較長(zhǎng)的反應(yīng)時(shí)間WriteInstruction(0 x38);顯示模式設(shè)置:16X2顯示,5X7點(diǎn)陣,8位數(shù)據(jù)接口delay(5);/延時(shí)5ms,給硬件一點(diǎn)反應(yīng)時(shí)間WriteInstruction(0 x38);delay(5);WriteInstruction(0 x38);/

13、連續(xù)三次,確保初始化成功delay(5);WriteInstruction(0 x0c);/顯示模式設(shè)置:顯示開(kāi),無(wú)光標(biāo),光標(biāo)不閃爍delay(5);WriteInstruction(0 x06);/顯示模式設(shè)置:光標(biāo)右移,字符不移delay(5);WriteInstruction(0 x01);/清屏幕指令,將以前的顯示內(nèi)容清除delay(5);WriteInstruction(0 x80);for(num=0;num10;num+)/讓液晶顯示日期WriteData(tablenum);delay(5);WriteInstruction(0 xc0);for(num=0;num12;num

14、+)/讓液晶顯示時(shí)間WriteData(table1num);delay(5);WriteInstruction(0 x80+20);for(num=0;num15;num+)WriteData(table2num);delay(5);WriteInstruction(0 xc0+20);for(num=0;num17;num+)WriteData(table3num);delay(5);TMOD=0 x11;/定時(shí)器中斷初始化TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;TH1=(65536-50000)/256;T

15、L1=(65536-50000)%256;ET1=1;TR1=0;/寫(xiě)年月日voidwrite_nyr(unsignedcharadd,unsignedchardate)unsignedchari,j;i=date/10;j=date%10;WriteInstruction(0 x80+add);WriteData(0 x30+i);WriteData(0 x30+j);/寫(xiě)時(shí)分秒voidwrite_sfm(unsignedcharadd,unsignedchardate)unsignedchari,j;i=date/10;j=date%10;WriteInstruction(0 xc0+ad

16、d);WriteData(0 x30+i);WriteData(0 x30+j);/寫(xiě)星期voidwrite_week(unsignedcharadd,unsignedchardate)WriteInstruction(0 x80+10+add);WriteData(0 x30+date);/寫(xiě)毫秒voidwrite_ms(unsignedcharadd,unsignedchardate)unsignedchari,j;i=date/10;j=date%10;WriteInstruction(0 x80+10+add);WriteData(0 x30+i);WriteData(0 x30+j)

17、;/記錄跑秒時(shí)間voidwrite_mb(unsignedcharadd,unsignedchardate)unsignedchari,j;i=date/10;j=date%10;WriteInstruction(0 xc0+20+add);WriteData(0 x30+i);WriteData(0 x30+j);/鍵盤(pán)掃描voidkeyscan()if(s1=0)/第一個(gè)鍵是否按下delay(5);if(s1=0)while(!s1);s1num+;if(s1num=1)/第一個(gè)鍵被按一次TR0=0;WriteInstruction(0 xc0+11);WriteInstruction(0

18、 x0f);if(s1num=2)WriteInstruction(0 xc0+8);if(s1num=3)WriteInstruction(0 xc0+5);if(s1num=4)WriteInstruction(0 x80+9);if(s1num=5)WriteInstruction(0 x80+6);if(s1num=6)WriteInstruction(0 x80+3);if(s1num=7)WriteInstruction(0 x80+20+5);/s1num=0;/循環(huán)一次if(s1num!=0)/如果功能鍵被按下if(s2=0)/第二個(gè)按下delay(5);if(s2=0)whi

19、le(!s2);if(s1num=1)/第二個(gè)鍵被按一次,秒鐘加一second+;if(second=60)second=0;write_sfm(10,second);WriteInstruction(0 x80+0 x40+11);if(s1num=2)/第二個(gè)鍵被按二次,分鐘加一minute+;if(minute=60)minute=0;write_sfm(7,minute);WriteInstruction(0 x80+0 x40+8);if(s1num=3)/第二個(gè)鍵被按三次,時(shí)鐘加一hour+;if(hour=24)hour=0;write_sfm(4,hour);WriteInst

20、ruction(0 x80+0 x40+5);if(s1num=4)/日期加一day+;if(day=32)day=1;write_nyr(8,day);WriteInstruction(0 x80+9);if(s1num=5)/月加一month+;if(month=13)month=1;write_nyr(5,month);WriteInstruction(0 x80+6);if(s1num=6)/年加一year+;if(year=99)year=0;write_nyr(2,year);WriteInstruction(0 x80+3);if(s1num=7)/星期加一week+;if(we

21、ek=8)week=1;write_week(15,week);WriteInstruction(0 x80+25);if(s3=0)/第三個(gè)鍵被按下delay(5);if(s3=0)while(!s3);if(s1num=1)second-;if(second=-1)second=59;write_sfm(10,second);WriteInstruction(0 x80+0 x40+11);if(s1num=2)minute-;if(minute=-1)minute=59;write_sfm(7,minute);WriteInstruction(0 x80+0 x40+8);if(s1nu

22、m=3)hour-;if(hour=-1)hour=23;write_sfm(4,hour);WriteInstruction(0 x80+0 x40+5);if(s1num=4)day-;if(day=0)day=31;write_nyr(8,day);WriteInstruction(0 x80+9);if(s1num=5)month-;if(month=0)month=12;write_nyr(5,month);WriteInstruction(0 x80+6);if(s1num=6)/秒減一/分減/時(shí)減一/日減一/月減一/年減year-;if(year=-1)year=99;write

23、_nyr(2,year);WriteInstruction(0 x80+3);/日期減一if(s1num=7)week-;if(week=0)week=7;write_week(15,week);WriteInstruction(0 x80+20+15);/保存并退出if(s4=0)s1num=0;WriteInstruction(0 x0c);TR0=1;if(s5=0)while(!s5);TR1=1;s5num+;if(s5num=2)write_mb(0,minu);write_mb(3,sec);write_mb(6,ms);if(s5num=3)write_mb(9,minu);w

24、rite_mb(12,sec);write_mb(15,ms);if(s5num=4)s5num=0;TR1=0;ms=0;sec=0;minu=0;write_ms(20,sec);write_ms(17,minu);write_ms(23,ms);write_mb(0,minu);write_mb(3,sec);write_mb(6,ms);write_mb(9,minu);write_mb(12,sec);write_mb(15,ms);/、/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx”mainfunction*1*1*1*1

25、*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx/voidmain(void)LcdInitiate();/調(diào)用LCD初始化函數(shù)while(1)keyscan();/*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx函數(shù)功能:定時(shí)器TO的中斷服務(wù)函數(shù)/TxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTxTx

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論