基于51單片機(jī)1602液晶時(shí)鐘設(shè)計(jì)C程序(閏年補(bǔ)償,月份調(diào)整)_第1頁(yè)
基于51單片機(jī)1602液晶時(shí)鐘設(shè)計(jì)C程序(閏年補(bǔ)償,月份調(diào)整)_第2頁(yè)
基于51單片機(jī)1602液晶時(shí)鐘設(shè)計(jì)C程序(閏年補(bǔ)償,月份調(diào)整)_第3頁(yè)
基于51單片機(jī)1602液晶時(shí)鐘設(shè)計(jì)C程序(閏年補(bǔ)償,月份調(diào)整)_第4頁(yè)
基于51單片機(jī)1602液晶時(shí)鐘設(shè)計(jì)C程序(閏年補(bǔ)償,月份調(diào)整)_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、#include#define uchar unsigned char#define uint unsigned intuchar code table= 2012-02-29 MON;uchar code table1= 23:59:55;uchar num,count,shi,fen,miao,nian,yue,ri,xingqi,s1num,flag;sbit lcden=P25; sbit lcdrs=P10;sbit lcdrw=P11;sbit s1=P30;sbit s2=P31;sbit s3=P32;sbit s4=P33;sbit feng=P23;/*延遲函數(shù)*/void

2、 delay(uint z)uint x,y;for(x=z;x0;x-)for(y=110;y0;y-);/*寫(xiě)命令*/void write_com(uchar com)lcdrs=0;lcdrw=0; P0=com;lcden=1; delay(5);lcden=0;/*寫(xiě)數(shù)據(jù)*/void write_data(uchar date)lcdrs=1;lcdrw=0;P0=date;lcden=1;delay(5);lcden=0;/*時(shí)分秒調(diào)節(jié)函數(shù)*/ void write_sfm(uchar add,uchar date) uchar shi,ge;shi=date/10;ge=date

3、%10;write_com(0x80+0x40+add);write_data(0x30+shi);write_data(0x30+ge); /*年月日調(diào)節(jié)函數(shù)*/ void write_nyr(uchar ad,uchar dat) uchar shi,ge;shi=dat/10;ge=dat%10;write_com(0x80+0x00+ad);write_data(0x30+shi);write_data(0x30+ge); /*星期顯示函數(shù)*/ void display_week() switch (xingqi) case 1: write_data(M); write_data(O

4、); write_data(N); write_com(0x80+0x00+14); break; case 2: write_data(T); write_data(U); write_data(E); write_com(0x80+0x00+14); break;case 3: write_data(W); write_data(E); write_data(D); write_com(0x80+0x00+14); break;case 4: write_data(T); write_data(H); write_data(U); write_com(0x80+0x00+14); brea

5、k; case 5: write_data(F); write_data(R); write_data(I); write_com(0x80+0x00+14); break; case 6: write_data(S); write_data(A); write_data(T); write_com(0x80+0x00+14); break; case 7: write_data(S); write_data(U); write_data(N); write_com(0x80+0x00+14); break;void keycan() /*光標(biāo)左移*/if(s1=0)delay(5);if(s

6、1=0) s1num+;while(!s1);if(s1num=1)TR0=0;write_com(0x80+0x40+11);write_data();write_com(0x80+0x40+10);/光標(biāo)重新回到閃爍點(diǎn),寫(xiě)光標(biāo)地址同樣加一write_com(0x0f); /光標(biāo)閃爍 if(s1num=2) write_com(0x80+0x40+11);write_data( );write_com(0x80+0x40+8);write_data();write_com(0x80+0x40+7);if(s1num=3) write_com(0x80+0x40+8);write_data(:

7、);write_com(0x80+0x40+5);write_data();write_com(0x80+0x40+4); if(s1num=4) write_com(0x80+0x40+5);write_data(:);write_com(0x80+15);write_data();write_com(0x80+14);if(s1num=5) write_com(0x80+15);write_data( );write_com(0x80+11);write_data();write_com(0x80+10); if(s1num=6) write_com(0x80+11);write_data

8、( );write_com(0x80+8);write_data();write_com(0x80+7); if(s1num=7) write_com(0x80+8);write_data(-);write_com(0x80+5);write_data();write_com(0x80+4); if(s1num=8)s1num=0;write_com(0x80+5);write_data(-);write_com(0x0c);TR0=1; /*光標(biāo)右移*/ /* if(s2=0)delay(5);if(s2=0) s1num-;while(!s2);if(s1num=1)TR0=0;write

9、_com(0x80+0x40+11);write_data();write_com(0x80+0x40+11);/光標(biāo)重新回到閃爍點(diǎn),寫(xiě)光標(biāo)地址同樣加一write_com(0x0f); /光標(biāo)閃爍 if(s1num=2) write_com(0x80+0x40+11);write_data( );write_com(0x80+0x40+8);write_data();write_com(0x80+0x40+8);if(s1num=3) write_com(0x80+0x40+8);write_data(:);write_com(0x80+0x40+5);write_data();write_c

10、om(0x80+0x40+5); if(s1num=4) write_com(0x80+0x40+5);write_data(:);write_com(0x80+15);write_data();write_com(0x80+15);if(s1num=5) write_com(0x80+15);write_data( );write_com(0x80+11);write_data();write_com(0x80+11); if(s1num=6) write_com(0x80+11);write_data( );write_com(0x80+8);write_data();write_com(

11、0x80+8); if(s1num=7) write_com(0x80+8);write_data(-);write_com(0x80+5);write_data(29&flag=1)/當(dāng)為閏年時(shí),如果ri=30,但是月份已經(jīng)加到2,這種情況ri必須等于29 ri=29; write_nyr(9,ri); if(yue=2&ri28&flag=0) /當(dāng)為平年時(shí),如果ri=30,但是月份已經(jīng)加到2,這種情況ri必須等于28 ri=28; write_nyr(9,ri); if(yue=4|yue=6|yue=9|yue=11)&(ri=31|ri=29|ri=28) ri=1; write_n

12、yr(9,ri); if(yue=13) yue=1; nian+; if(nian%40) write_nyr(9,28); write_nyr(3,nian); write_nyr(6,yue); write_com(0x80+0x00+7);if(s1num=7) nian+; if(nian=100) nian=0; flag=0; if(nian%4=0) flag=1; write_nyr(3,nian); write_com(0x80+0x00+4);/*按鍵減*/if(s4=0)delay(5);if(s4=0)while(!s4);if(s1num=1)miao-;if(mi

13、ao=-1)miao=59;write_sfm(9,miao);write_com(0x80+0x40+10);if(s1num=2)fen-;if(fen=-1)fen=59;write_sfm(6,fen);write_com(0x80+0x40+7);if(s1num=3)shi-;if(shi=-1)shi=23;write_sfm(3,shi);write_com(0x80+0x40+4);if(s1num=4)xingqi-; if(xingqi=0)xingqi=7;write_com(0x80+0x00+12); display_week();if(s1num=5)ri-; i

14、f(ri=0&(yue=1|yue=3|yue=5|yue=7|yue=8|yue=10|yue=12) ri=30; /防止當(dāng)yue=12時(shí),當(dāng)yue減到11時(shí),ri任然等于31時(shí)這種不允許情況出現(xiàn) yue-; if(yue=2) if(flag=1) ri=29; else ri=28; write_nyr(6,yue); if(yue=0) yue=12; ri=31; write_nyr(9,ri); write_nyr(6,yue); if(ri=0&(yue=4|yue=6|yue=9|yue=11) ri=31;/按下減小按鈕,yue減到3或5或8或10,為大月 yue-; wr

15、ite_nyr(6,yue); if(flag=1) /閏年標(biāo)志位 if(ri=0&yue=2) ri=29;yue-; write_nyr(6,yue); if(flag=0) /平年標(biāo)志位 if(ri=0&yue=2) ri=28; yue-; write_nyr(6,yue); write_nyr(9,ri); write_com(0x80+0x00+10);if(s1num=6) yue-; if(yue=2&ri29&flag=1) ri=29; write_nyr(9,ri); if(yue=2&ri28&flag=0) ri=28; write_nyr(9,ri); if(yue

16、=0) yue=12; nian-; write_nyr(3,nian); write_nyr(6,yue); if(yue=4|yue=6|yue=9|yue=11)&(ri=31|ri=29|ri=28) ri=1; write_nyr(9,ri); write_com(0x80+0x00+7); if(s1num=7) nian-;if(nian=-1)nian=99;flag=0; /清除標(biāo)志位if(nian%4=0) flag=1; write_nyr(3,nian);write_com(0x80+0x00+4); /*初始化*/void init()write_com(0x38);

17、write_com(0x0c);write_com(0x06);write_com(0x01); write_com(0x80+0x00); for(num=0;num15;num+)write_data(tablenum);delay(5); write_com(0x80+0x40);for(num=0;num11;num+)write_data(table1num);delay(5); shi=23; fen=59; miao=55; xingqi=1; ri=29; yue=2; nian=12; if(nian%4=0) flag=1; TMOD=0x01; TH0=(65536-50

18、000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; /*主函數(shù)*/ void main() init();/初始化 while(1) keycan(); /*啟動(dòng)定時(shí)器*/void timer() interrupt 1 TH0=(65536-50000)/256; TL0=(65536-50000)%256;count+; if(count=18) count=0; miao+; if(miao=60) miao=0;fen+; if(fen=60) fen=0; feng=0; delay(500); feng=1; shi+; if(shi=24) shi=0; ri+; xingqi+; if(xingqi=8) xingqi=1; write_com(0x80+0x00+12); display_week(); if(ri=32&(yue=1|yue=3|yue=5|yue=7|yue=8|yue=10|yue=12) ri=1; yue+; if(yue=13) yue=1; nian+; if(nian=99) nian=0; if(nian%4=0) flag=1;f

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論