單片機(jī)實(shí)驗(yàn)報(bào)告_第1頁(yè)
單片機(jī)實(shí)驗(yàn)報(bào)告_第2頁(yè)
單片機(jī)實(shí)驗(yàn)報(bào)告_第3頁(yè)
單片機(jī)實(shí)驗(yàn)報(bào)告_第4頁(yè)
單片機(jī)實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩42頁(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)介

PAGE1單片機(jī)應(yīng)用系統(tǒng)設(shè)計(jì)報(bào)告題目單片機(jī)應(yīng)用系統(tǒng)設(shè)計(jì)學(xué)院信息學(xué)院專業(yè)電氣工程及自動(dòng)化班級(jí)12電氣升本學(xué)生姓名朱婉婉學(xué)號(hào)1230400217月16日至7月28日共11天13年7月18日一、設(shè)計(jì)內(nèi)容及要求必做實(shí)驗(yàn)內(nèi)容:時(shí)鐘09年06月24日22時(shí)33分24秒1.使用中文液晶128x64點(diǎn)陣LCD,采用16點(diǎn)陣字庫(kù)顯示當(dāng)前時(shí)間“時(shí)鐘09年06月24日22時(shí)33分24秒2.用4個(gè)按鍵設(shè)置現(xiàn)在時(shí)間:K1進(jìn)入設(shè)置現(xiàn)在時(shí)間;K2調(diào)整小時(shí);K3調(diào)整分;K4設(shè)置完成。3.增加鬧鈴功能,時(shí)間到了使用音樂(lè)聲可選實(shí)驗(yàn)內(nèi)容:4.增加鬧鈴功能,時(shí)間到發(fā)出聲響并啟動(dòng)繼電器5.增加秒表計(jì)數(shù)功能,精度為0.01秒6.增加萬(wàn)年歷顯示“年月日”課程設(shè)計(jì)要求方案設(shè)計(jì)前要求完成設(shè)計(jì)報(bào)告,每個(gè)組一份;方案實(shí)施過(guò)程中完善設(shè)計(jì)報(bào)告,每個(gè)成員獨(dú)立進(jìn)行;方案實(shí)施結(jié)束,經(jīng)過(guò)指導(dǎo)老師驗(yàn)收后完成設(shè)計(jì)報(bào)告,每個(gè)成員獨(dú)立完成,其中設(shè)計(jì)圖紙每個(gè)組只需要1份。目錄TOC\o"1-2"\h\u7724一、概述 1349071、總體功能 13148432、實(shí)驗(yàn)要求 136274二、硬件電路圖及說(shuō)明 14112861、硬件電路圖 錯(cuò)誤!未定義書簽。173302、12864LCD液晶顯示屏 15112863、按鍵功能 錯(cuò)誤!未定義書簽。112864、實(shí)時(shí)時(shí)鐘芯片S-3530A 錯(cuò)誤!未定義書簽。15865三、電路及程序設(shè)計(jì) 7763四、設(shè)計(jì)特點(diǎn) 錯(cuò)誤!未定義書簽。3464五、調(diào)試 錯(cuò)誤!未定義書簽。112861、主循環(huán)程序流程 錯(cuò)誤!未定義書簽。173302、關(guān)于3530讀出數(shù)據(jù)的更改 15112863、關(guān)于秒表的設(shè)置 錯(cuò)誤!未定義書簽。112864、關(guān)于時(shí)間的設(shè)置 錯(cuò)誤!未定義書簽。173305、遇到的具體問(wèn)題 15112866、注意事項(xiàng) 錯(cuò)誤!未定義書簽。18863六、總結(jié)及體會(huì) 19七、22552使用說(shuō)明書 錯(cuò)誤!未定義書簽。八、13771程序及簡(jiǎn)單注解 錯(cuò)誤!未定義書簽。112861、main.c 錯(cuò)誤!未定義書簽。173302、I2C.c 15112863、LCD.c 錯(cuò)誤!未定義書簽。一、概述1、總體功能本次設(shè)計(jì)時(shí)鐘電路,使用了STC89C51單片機(jī)芯片控制電路,單片機(jī)控制電路簡(jiǎn)單且省去了很多復(fù)雜的線路,使得電路簡(jiǎn)明易懂,使用鍵盤鍵上的按鍵來(lái)調(diào)整時(shí)鐘的時(shí)、分、秒,用一揚(yáng)聲器來(lái)進(jìn)行定時(shí)提醒,同時(shí)使用C語(yǔ)言程序來(lái)控制整個(gè)時(shí)鐘顯示,使得編程變得更容易,這樣通過(guò)四個(gè)模塊:鍵盤、芯片、揚(yáng)聲器、顯示屏即可滿足設(shè)計(jì)要求。2、實(shí)驗(yàn)要求必做實(shí)驗(yàn)內(nèi)容:1.使用中文液晶128x64點(diǎn)陣LCD,采用16點(diǎn)陣字庫(kù)顯示當(dāng)前時(shí)間“時(shí)時(shí):分分:秒秒”2.用4個(gè)按鍵設(shè)置現(xiàn)在時(shí)間:K1進(jìn)入設(shè)置日期;(K1=1)時(shí)鐘09年06月24日時(shí)鐘09年06月24日22時(shí)33分24秒K3調(diào)整月;K4調(diào)整日。K1進(jìn)入設(shè)置現(xiàn)在時(shí)間;(K1=2)K2調(diào)整小時(shí);K3調(diào)整分;K4調(diào)整秒。K1設(shè)置完成(K1=3)增加鬧鈴功能,時(shí)間到了使用音樂(lè)聲(指示燈閃動(dòng)10秒)可選實(shí)驗(yàn)內(nèi)容增加鬧鈴功能,三次鬧鈴增加秒表計(jì)數(shù)功能,精度為0.01秒0.00-200.00增加萬(wàn)年歷顯示“年月日”二月28天、29天增加星期顯示增加整點(diǎn)鬧鈴指示燈閃動(dòng)5次增加整點(diǎn)鬧鈴開關(guān)9秒表反字9秒表小圖形被設(shè)置的數(shù)字閃動(dòng),其他自己認(rèn)為可添加的內(nèi)容課程設(shè)計(jì)要求方案設(shè)計(jì)前要求完成設(shè)計(jì)報(bào)告,每個(gè)組一份;方案實(shí)施過(guò)程中完善設(shè)計(jì)報(bào)告,每個(gè)成員獨(dú)立進(jìn)行;方案實(shí)施結(jié)束,經(jīng)過(guò)指導(dǎo)老師驗(yàn)收后完成設(shè)計(jì)報(bào)告,每個(gè)成員獨(dú)立完成,其中設(shè)計(jì)圖紙每個(gè)組只需要1份二、硬件電路圖及說(shuō)明1、硬件電路圖LCD時(shí)鐘控制系統(tǒng)利用C8051F020芯片作為控制中心,配合液晶顯示128*64液晶顯示模塊、獨(dú)立式鍵盤模塊、實(shí)時(shí)時(shí)鐘/日歷芯片模塊等電路,實(shí)現(xiàn)日歷時(shí)鐘實(shí)現(xiàn)顯示年月日時(shí)分秒??傮w設(shè)計(jì)方框圖如圖1所示:圖12、12864LCD液晶顯示屏帶中文字庫(kù)的128X64是一種具有4位/8位并行、2線或3線串行多種接口方式,內(nèi)部含有國(guó)標(biāo)一級(jí)、二級(jí)簡(jiǎn)體中文字庫(kù)的點(diǎn)陣圖形液晶顯示模塊;其顯示分辨率為128×64,內(nèi)置8192個(gè)16*16點(diǎn)漢字,和128個(gè)16*8點(diǎn)ASCII字符集利用該模塊靈活的接口方式和簡(jiǎn)單、方便的操作指令,可構(gòu)成全中文人機(jī)交互圖形界面??梢燥@示8×4行16×16點(diǎn)陣的漢字也可完成圖形顯示低電壓低功耗是其又一顯著特點(diǎn)。由該模塊構(gòu)成的液晶顯示方案與同類型的圖形點(diǎn)陣液晶顯示模塊相比,不論硬件電路結(jié)構(gòu)或顯示程序都要簡(jiǎn)潔得多,且該模塊的價(jià)格也略低于相同點(diǎn)陣的圖形液晶模塊。12864接口定義及其與C8051F020的接口:引腳及內(nèi)部結(jié)構(gòu)如圖2所示:圖2液晶顯示電路3、按鍵電路K1連接P3.0口,K2連接P3.1口,K3;連接P3.2口,K4連接P3.3口鍵盤是由若干按鍵組成的開關(guān)矩陣,它是微型計(jì)算機(jī)最常用的輸入設(shè)備,用戶可以通過(guò)鍵盤向計(jì)算機(jī)輸入指令、地址和數(shù)據(jù)。一般單片機(jī)系統(tǒng)中采和非編碼鍵盤,非編碼鍵盤是由軟件來(lái)識(shí)別鍵盤上的閉合鍵,它具有結(jié)構(gòu)簡(jiǎn)單,使用靈活等特點(diǎn),因此被廣泛應(yīng)用于單片機(jī)系統(tǒng)。按鍵開關(guān)的抖動(dòng)問(wèn)題,鍵盤與單片機(jī)的連接組成鍵盤的按鍵有觸點(diǎn)式和非觸點(diǎn)式兩種,單片機(jī)中應(yīng)用的一般是由機(jī)械觸點(diǎn)構(gòu)成的。當(dāng)開關(guān)S未被按下時(shí),P3.0輸入為高電平,S閉合后,P3.0輸入為低電平。而按鍵會(huì)有抖動(dòng)現(xiàn)象,因此必須考慮如何去除抖動(dòng),常用的去抖動(dòng)的方法有兩種:硬件方法和軟件方法。單片機(jī)中常用軟件法。軟件法其實(shí)很簡(jiǎn)單,就是在單片機(jī)獲得P3.0口為低的信息后,不是立即認(rèn)定S1已被按下,而是延時(shí)10毫秒或更長(zhǎng)一些時(shí)間后再次檢測(cè)P3.0口,如果仍為低,說(shuō)明S1的確按下了,這實(shí)際上是避開了按鍵按下時(shí)的抖動(dòng)時(shí)間。而在檢測(cè)到按鍵釋放后(P3.0為高)再延時(shí)5-10個(gè)毫秒,消除后沿的抖動(dòng),然后再對(duì)鍵值處理。本次實(shí)驗(yàn)去抖動(dòng)采用軟件方式。四個(gè)按鍵分別接到P3.1、P3.2、P3.3和P3.4。對(duì)于這種鍵各程序可以采用不斷查詢的方法,功能就是:檢測(cè)是否有鍵閉合,如有鍵閉合,則去除鍵抖動(dòng),判斷鍵號(hào)并轉(zhuǎn)入相應(yīng)的鍵處理。4、實(shí)時(shí)時(shí)鐘芯片S-3530AS-3530是一款低功耗的CMOS實(shí)時(shí)時(shí)鐘/日歷芯片,它提供二個(gè)中斷輸出和掉電檢測(cè)器,所有的地址和數(shù)據(jù)通過(guò)I2C總線接口串行傳遞。最大總線速度為400Kbits/s,每次讀寫數(shù)據(jù)后,內(nèi)嵌的字地址寄存器會(huì)自動(dòng)增加。(1)器件特性:低工作電流:典型值為0.7μA(VDD=3.0V);世紀(jì)標(biāo)志;大工作電壓范圍:1.0~5.5V;BCD碼設(shè)置時(shí)間參數(shù)低休眠電流;典型值為0.25μA(VDD=1.8~5.5V時(shí));穩(wěn)壓電路報(bào)警和定時(shí)器;掉電檢測(cè)器;內(nèi)部集成的振蕩器電容;I2C總線從地址:讀:0A3H;寫:0A2H;三、電路與程序設(shè)計(jì)1、程序流程圖主程序:開始↓關(guān)看門狗程序↓初始化系統(tǒng)時(shí)鐘↓初始化定時(shí)器1↓開中斷↓調(diào)用函數(shù)TestI2C()↓結(jié)束子程序TestI2C():開始↓讀取3530數(shù)據(jù)↓時(shí)間賦初值↓將初值讀入3530↓清屏↓在16,0處顯示05年01月01日,在16,2處顯示00時(shí)00分00秒↓讀取3530數(shù)據(jù)↓調(diào)用函數(shù)set_value()↓分為0且秒小于11↓Y整點(diǎn)報(bào)時(shí)LED燈閃爍↓調(diào)用函數(shù)alarm_check()↓刷新顯示時(shí)分秒,刷新顯示年月日↓Nmiaobiao_on為偶且不為0N↓Y顯示秒表↓miaobiao_on為0↓Y顯示星期↓延時(shí)100ms↓設(shè)置flag1標(biāo)志位為1按鍵判斷程序set_value():根據(jù)設(shè)計(jì)原則,判斷按鍵并作出相應(yīng)反應(yīng).開始↓讀取按鍵值↓有鍵按下且flag1=1↓flag=0↓按下的鍵為K1↓flag=1;key2=1;flag1=0;在(112,0)顯示“年”↓按下的鍵為K2↓flag=3;flag1=0;在(112,0)顯示“鬧”↓按下的鍵為K3↓flag=7;miaobiao_on=1;flag1=0;在(16,4)顯示“秒表:XXX:XX”↓flag=1↓按下的鍵為K1↓flag=2;key2=1;flag1=0;在(112,0)顯示“時(shí)”↓按下的鍵為K2↓key2++;flag1=0;↓key2=2↓在(112,0)顯示“月”↓key2=3↓在(112,0)顯示“日”↓按下的鍵為K3↓key2=1↓年加1,星期根據(jù)平年閏年加1或2↓將數(shù)據(jù)讀入3530↓更新星期和年的顯示flag1=0;↓key2=2↓月加1,星期根據(jù)月的日期增加↓將數(shù)據(jù)讀入3530↓更新星期和月的顯示flag1=0;↓key2=3↓月加1,星期根據(jù)月的日期增加↓將數(shù)據(jù)讀入3530↓更新星期和月的顯示flag1=0;↓按下的鍵為K4↓退出時(shí)鐘設(shè)置flag=0;flag1=0;key2=0;清除提示字符↓flag=2↓按下的鍵為K1↓退出時(shí)鐘設(shè)置flag=0;flag1=0;key2=0;清除提示字符↓按下的鍵為K2↓key2++;flag1=0;↓key2=2↓在(112,0)顯示分↓key2=3↓在(112,0)顯示秒↓按下的鍵為K3↓key2=1↓時(shí)加1↓將更改的數(shù)據(jù)讀入3530↓刷新顯示時(shí),flag1=0;↓key2=2↓分加1↓將更改的數(shù)據(jù)讀入3530↓刷新顯示分,flag1=0;↓key2=3↓秒加1↓將更改的數(shù)據(jù)讀入3530↓刷新顯示秒,flag1=0;↓按下的鍵為K4↓退出時(shí)鐘設(shè)置flag=0;flag1=0;key2=0;清楚提示字符↓flag=3↓按下的鍵為K2↓alarm_num不等于0↓flag=4;flag1=0;在(00,6)顯示“1”在(64,6)顯示第一個(gè)鬧鐘設(shè)置時(shí)間↓flag=0;flag1=0;退出鬧鐘功能,清除提示字符↓按下的鍵為K3↓alarm_num<3↓alarm_num加1↓alarm_num=0;關(guān)鬧鐘↓flag=4↓按下的鍵為K2↓alarm_num>1↓flag=5;在(00,6)顯示2在(64,6)顯示第二個(gè)鬧鐘設(shè)置時(shí)間flag1=0;開鬧鐘在(112,6)顯示“開”↓flag=0;flag1=0;退出鬧鐘設(shè)置,清楚提示字符↓按下的鍵為K3↓鬧鐘1的時(shí)加1,刷新顯示鬧鐘時(shí)間,flag1=0;↓按下的鍵為K4↓鬧鐘1的秒加1,刷新顯示鬧鐘時(shí)間,flag1=0;↓flag=5↓按下的鍵為K2↓alarm_num>2↓flag=6;在(00,6)顯示3在(64,6)顯示第二個(gè)鬧鐘設(shè)置時(shí)間flag1=0;開鬧鐘在(112,6)顯示“開”↓flag=0;flag1=0;退出鬧鐘設(shè)置,清楚提示字符↓按下的鍵為K3↓鬧鐘1的時(shí)加1,刷新顯示鬧鐘時(shí)間,flag1=0;↓按下的鍵為K4↓鬧鐘1的秒加1,刷新顯示鬧鐘時(shí)間,flag1=0;↓flag=6↓按下的鍵為K1↓↓按下的鍵為K2↓↓按下的鍵為K3↓↓按下的鍵為K4↓↓flag=7↓按下的鍵為K1↓↓按下的鍵為K2↓↓按下的鍵為K3↓↓按下的鍵為K4↓↓鬧鐘判斷程序alarm_check():判斷鬧鐘是否開,根據(jù)鬧鐘開啟數(shù)量判斷是否到設(shè)定時(shí)間,若到,則啟動(dòng)LED燈閃四.設(shè)計(jì)特點(diǎn):1.該時(shí)鐘由四個(gè)按鍵控制,按鍵功能分明:K1進(jìn)入設(shè)置日期;(K1=1)K2調(diào)整年;K3調(diào)整月;K4調(diào)整日。K1進(jìn)入設(shè)置現(xiàn)在時(shí)間;(K1=2)K2調(diào)整小時(shí);K3調(diào)整分;K4調(diào)整秒。K1設(shè)置完成(K1=3)進(jìn)入鬧鈴設(shè)置。2.秒表采用定時(shí)器中斷控制,計(jì)時(shí)精確。K3一次進(jìn)入秒表。K3兩次開始計(jì)時(shí)。K3三次計(jì)時(shí)停止。K4退出秒表。3.顯示頁(yè)面結(jié)構(gòu)清晰,功能明確。平時(shí)若無(wú)設(shè)置,則只顯示年月日,時(shí)分秒以及星期4.進(jìn)入設(shè)置后會(huì)出現(xiàn)一些提示字符,表述明了。五.調(diào)試:1.主循環(huán)程序流程實(shí)驗(yàn)初期,原來(lái)的流程是測(cè)試按鍵,完成所有操作后再刷新顯示,進(jìn)入主循環(huán),但是,這樣在測(cè)試按鍵,等待操作時(shí)會(huì)造成較大的延時(shí)。因此該方案未錄取。最后采用的方案是:檢測(cè)到一次按鍵,就更改flag和flag1標(biāo)志位,記錄按鍵次序后就進(jìn)入主循環(huán),然后繼續(xù)檢測(cè)有無(wú)按鍵操作,這樣對(duì)于程序就基本不會(huì)造成延時(shí),而且程序的流程也更清晰。關(guān)于標(biāo)志位:flag用來(lái)記錄之前按鍵次數(shù)和次序flag=0表示之前無(wú)按鍵操作flag=1表示K1按一下flag=2表示K1按兩下flag=3表示K2按一下flag=4表示K2按兩下flag=5表示K2按三下flag=6表示K2按四下flag=7表示K3按一下flag1表示之前有無(wú)按鍵按下flag1=1,表示無(wú)按鍵,flag1=0,表示已有按鍵按下過(guò)。2.關(guān)于3530讀出數(shù)據(jù)的更改遇到的具體問(wèn)題:時(shí)間設(shè)置時(shí),10以下的都能正確顯示,兩位數(shù)的就不會(huì)正確顯示。在設(shè)置“時(shí)”時(shí),只能加到12,而程序中的時(shí)鐘為24小時(shí)制,所以不正確。原因:3530中讀出的數(shù)據(jù)格式為BCD碼,而程序中修改則按照16進(jìn)制進(jìn)行。所以會(huì)有數(shù)據(jù)錯(cuò)誤。解決方法:在設(shè)置時(shí)鐘時(shí)間時(shí),要先讀出3530數(shù)據(jù),更改后再讀入3530中,而3530中的數(shù)據(jù)存放為BCD碼,讀出后并不表示時(shí)間的真實(shí)數(shù)據(jù),因此,我編寫了兩個(gè)轉(zhuǎn)化函數(shù):change()將16進(jìn)制轉(zhuǎn)化為BCD碼fchange()將BCD碼轉(zhuǎn)化為16進(jìn)制讀出數(shù)據(jù)后先將其轉(zhuǎn)化為16進(jìn)制,進(jìn)行操作后再轉(zhuǎn)化為BCD碼,讀入3530數(shù)據(jù)更改中,因?yàn)椤皶r(shí)”的數(shù)據(jù)表示只需低4位和高4位中的低兩位,所以最高2位中會(huì)有一些臟數(shù)據(jù),在讀出后應(yīng)先與上0x3f再進(jìn)行轉(zhuǎn)化操作。3.關(guān)于秒表設(shè)置秒表采用定時(shí)器1,初值為(65536-18432),并利用一個(gè)計(jì)數(shù)變量miaobiao,初值為10,中斷中重新賦初值,每次中斷miaobiao減1,減至0時(shí),秒表計(jì)數(shù)變量加1,miaobiao重新賦值為10!4.關(guān)于時(shí)間的設(shè)置在時(shí)間設(shè)置時(shí)遇到的問(wèn)題基本上是因?yàn)榭紤]的不夠周全,剛開始時(shí),沒(méi)考慮到閏年,大小月等情況,因此,閏年的二月不能調(diào)出29號(hào),大小月也不能區(qū)別,遇到這個(gè)問(wèn)題后就開始更改程序的細(xì)節(jié)問(wèn)題,使得設(shè)置時(shí)間時(shí)所有的日子都能設(shè)置出。要考慮的設(shè)置:年有閏年,平年,月有大小月,星期要隨著年,月,日的更改而更改。5.遇到的具體問(wèn)題在運(yùn)行時(shí),顯示屏幕卡屏。只要一運(yùn)行秒表程序,很快就會(huì)使程序卡在某一點(diǎn)。原因:在原來(lái)的中斷程序中還有加入顯示代碼,造成在運(yùn)行時(shí),顯示屏幕卡屏。因?yàn)槠聊恢酗@示的時(shí)間和秒表分別由兩個(gè)計(jì)數(shù)器控制,在刷新時(shí)因?yàn)橛?jì)數(shù)器沖突而造成了卡屏的現(xiàn)象。那是因?yàn)槠聊恢酗@示的時(shí)間和秒表分別由兩個(gè)計(jì)數(shù)器控制,在刷新時(shí)因?yàn)橛?jì)數(shù)器沖突而造成了卡屏的現(xiàn)象。更改方法:將中斷程序中的顯示代碼取出,直接放在主循環(huán)程序中,這樣就能順利運(yùn)行了。6.注意事項(xiàng)在設(shè)計(jì)秒表時(shí),定時(shí)器1的主要程序放在main.c文件中,而一些顯示程序則在I2C.c文件中,因此,在調(diào)用這些變量時(shí)就會(huì)出現(xiàn)編譯錯(cuò)誤。為解決該現(xiàn)象,我在main.c文件中先編寫了一個(gè)小的調(diào)用顯示程序,在需要顯示時(shí)再調(diào)用該程序,就解決了變量調(diào)用問(wèn)題。六.總結(jié)及體會(huì):本次課程設(shè)計(jì)是用AT89S51單片機(jī)CPU及LCM1602設(shè)計(jì)一個(gè)數(shù)字時(shí)鐘,經(jīng)過(guò)一個(gè)了預(yù)先設(shè)定的功能,設(shè)計(jì)主要用到的元件不多,最主要的是程序也比較長(zhǎng)比較麻煩,同時(shí)也遇到了少量困難,尤其是關(guān)于校時(shí)模塊的設(shè)計(jì)實(shí)現(xiàn)。關(guān)于顯示模塊,在以前的實(shí)驗(yàn)中做過(guò),所以問(wèn)題很容易解決。學(xué)以致用,將從書本上學(xué)到的知識(shí)應(yīng)用于實(shí)踐,學(xué)會(huì)了初步的電子電路仿真設(shè)計(jì)雖然過(guò)程中遇到了一些困難,但是在解決這些問(wèn)題的過(guò)程無(wú)疑也是對(duì)自己自身專業(yè)素質(zhì)的一種提高。當(dāng)最終調(diào)試成功的時(shí)候也是對(duì)自己的一種肯定。此次的設(shè)計(jì)作業(yè)不僅增強(qiáng)了自己在專業(yè)設(shè)計(jì)方面的信心,鼓舞了自己,更是一次興趣的培養(yǎng),為自己以后的學(xué)習(xí)方向的明確了重點(diǎn)。另外在這次實(shí)驗(yàn)中我們遇到了不少的問(wèn)題針對(duì)不同的問(wèn)題我們采取不同的解決方法,最終一一解決設(shè)計(jì)中遇到的問(wèn)題。在我們?cè)?jīng)遇到不懂的問(wèn)題時(shí),利用網(wǎng)上的資源,搜索查找得到需要的信息七.使用說(shuō)明書:該產(chǎn)品為電子時(shí)鐘,能顯示年月日,時(shí)分秒及星期,有秒表功能,鬧鐘功能(注1),會(huì)進(jìn)行整點(diǎn)報(bào)時(shí),有四個(gè)按鍵控制功能的選擇使用,下文中分別稱為K1,K2,K3,K4XX年XX月XX日XXXX時(shí)XX分XX秒星期X按鍵說(shuō)明:K1:進(jìn)入時(shí)間設(shè)置K1按一次,設(shè)置年月日K1按兩次,設(shè)置時(shí)分秒K2移位,K3加1,K4退出K1按三次,退出設(shè)置如右圖,在時(shí)間設(shè)置時(shí),屏幕右上角會(huì)根據(jù)按鍵操作而出現(xiàn)“時(shí)”“分”“秒”“年”“月”“日”提示當(dāng)前操作的作用對(duì)象。K2:進(jìn)入鬧鐘設(shè)置XX年XX月XX日XXXX時(shí)XX分XX秒星期XK3選擇開鬧鐘的次數(shù)(0-3),若開的鬧鐘個(gè)數(shù)為零則表示鬧鐘關(guān)閉K2進(jìn)入鬧鐘時(shí)間設(shè)置,K3時(shí)加,K4分加再按K2退出鬧鐘操作界面如右圖:右上角會(huì)出現(xiàn)“鬧”提示字。最下一行顯示當(dāng)前設(shè)置鬧鐘時(shí)間,鬧鐘次數(shù),及鬧鐘開關(guān)狀況。XX年XX月XX日XX時(shí)XX分XX秒秒表:XXX:XXK3:開啟秒表K3開始/停止計(jì)時(shí)K4退出秒表.秒表界面:注1:鬧鐘功能,本產(chǎn)品鬧鐘最多能設(shè)置3個(gè)不同時(shí)間,可選擇開鬧鐘的次數(shù),例如,若選擇次數(shù)為1時(shí),則只會(huì)對(duì)鬧鐘一設(shè)置的時(shí)間作出反應(yīng)(LED燈閃),次數(shù)為2時(shí),則對(duì)前兩個(gè)鬧鐘設(shè)定時(shí)間作出反應(yīng),因此,建議將常用的鬧鐘時(shí)間設(shè)在前面.八.程序及簡(jiǎn)單注釋:1、main.c#include"c8051f020.h"#include<intrins.h>voidDelay1us(unsignedcharus){ while(us) { _nop_();_nop_();_nop_();_nop_();_nop_(); --us; }}voidSYSCLK_Init(void){inti;//delaycounterOSCXCN=0x65;//startexternaloscillatorwithfor(i=0;i<256;i++);//Waitforosc.tostartupwhile(!(OSCXCN&0x80));//Waitforcrystalosc.tosettleOSCICN=0x88;}#definePRT0CFP0MDOUT#definePRT1CFP1MDOUT#definePRT2CFP2MDOUTvoidPORT_Init(void){XBR0=0x07;//EnableSMBus,SPI0,andUART0//XBR1=0x04;XBR2=0x40;//Enablecrossbarandweakpull-ups//EMI0CF=0x27;//EMI0TC=0x21;EMI0TC=0x21;EMI0CF=0x2f;//EMIF端口接到P4-P7,選擇復(fù)用方式,工作模式為不帶塊選擇。P74OUT=0x3F;P0MDOUT=0x00;P1MDOUT|=0x1f; //P1.2-P1.5推挽輸出}voidSPI0_Init(void){SPI0CFG=0x03;//datasampledon1stSCKrisingedgeSPI0CFG|=0xC0; //CKPOL=1;SPI0CN=0x03;//Mastermode;SPIenabled;flaSPI0CKR=SYSCLK/2/8000000-1;}unsignedcharCount1ms;voidTimer0_Init(void){ CKCON|=0x8; TMOD|=0x1; //16Bit Count1ms=10; TR0=0; //STOPTimer0 TH0=(-SYSCLK/1000)>>8; //setTimer0tooverflowin1ms TL0=-SYSCLK/1000; TR0=1; //STARTTimer0 IE|=0x2;}voidTimer1_Init(void){ CKCON|=0x8; TMOD|=0x10; //16Bit TR1=0;//STOPTimer0 TH1=(65535-18432)/256; //setTimer0tooverflowin1ms TL1=(65535-18432)%256; ET1=1;}voidTimer0_ISR(void)interrupt1//1ms{ TH0=(-SYSCLK/1000)>>8; TL0=-SYSCLK/1000; if(Count1ms)Count1ms--;}voidDelay1ms(unsignedcharT){ Count1ms=T; while(Count1ms);}voidDelay1s(unsignedcharT){ while(T) { Delay1ms(200); Delay1ms(200); Delay1ms(200); Delay1ms(200); Delay1ms(200); T--; }}voidTestLCD(void);voidTestI2C(void);voidmain(void){ WDTCN=0xde; WDTCN=0xad;//關(guān)看門狗 SYSCLK_Init();//初始化時(shí)鐘 Timer0_Init(); //初始化定時(shí)器Timer1_Init(); //初始化定時(shí)器 PORT_Init();//初始化IO口// SPI0_Init();//初始化SPI0// CPT1CN|=0x80; //使能比較器1// REF0CN=0x03;//使能片內(nèi)參考電壓// DAC0CN|=0x80; //使能DAC0// DAC0H=0;DAC0L=0;EA=1; //開中斷// TestLCD();// Test7279(0); TestI2C();}2、I2c.c#include"c8051f020.h" //SFRdeclarations////GlobalCONSTANTS//sbit K1=P3^0;sbit K2=P3^1;sbit K3=P3^2;sbit K4=P3^3;sbit K5=P3^4;sbit P1_6=P1^6;sbit P1_7=P1^7;#define WRITE 0x00 //SMBusWRITEcommand#define READ 0x01 //SMBusREADcommand//Deviceaddresses(7bits,lsbisadon'tcare)#define CLOCK3530_ADDRESS_RESET 0x60 //1ack#define CLOCK3530_ADDRESS_STATUS 0x62 //2ack#define CLOCK3530_ADDRESS_DATEHOUR 0x64 //8ackyearmonthdayweekhourminutesecond#define CLOCK3530_ADDRESS_HOUR 0x66 //4ackhourminutesecond#define CLOCK3530_ADDRESS_INT1 0x68 //3ack#define CLOCK3530_ADDRESS_INT2 0x6A //3ackunion{unsignedcharClockString[7];structRealClock { unsignedcharYear,Month,Day,Week,Hour,Minute,Second; }RT;}RealTime;//SMBusstates://MT=MasterTransmitter//MR=MasterReceiver#define SMB_BUS_ERROR 0x00 //(allmodes)BUSERROR#define SMB_START 0x08 //(MT&MR)STARTtransmitted#define SMB_RP_START 0x10 //(MT&MR)repeatedSTART#define SMB_MTADDACK 0x18 //(MT)Slaveaddress+Wtransmitted;#define SMB_MTADDNACK 0x20 //(MT)Slaveaddress+Wtransmitted; //NACKreceived#define SMB_MTDBACK 0x28 //(MT)databytetransmitted;ACKrec'vd#define SMB_MTDBNACK 0x30 //(MT)databytetransmitted;NACKrec'vd#define SMB_MTARBLOST 0x38 //(MT)arbitrationlost#define SMB_MRADDACK 0x40 //(MR)Slaveaddress+Rtransmitted; //ACKreceived#define SMB_MRADDNACK 0x48 //(MR)Slaveaddress+Rtransmitted; //NACKreceived#define SMB_MRDBACK 0x50 //(MR)databyterec'vd;ACKtransmitted#define SMB_MRDBNACK 0x58 //(MR)databyterec'vd;NACKtransmitted////GlobalVARIABLES//charCOMMAND; //Holdstheslaveaddress+R/WbitforuseintheSMBusISR.unsignedchar*I2CDataBuff; intn=0,i,flag=1,m=0,h,f,hm=0,s=0,bs=0,l=0,q=0,q1=1,h1,h2,f1,f2;charBYTE_NUMBER; //UsedbyISRtocheckwhatdatahasjustbeen //sent-Highaddressbyte,Lowbyte,ordatabyteunsignedcharHour,Minute,Year,Month,Day,Week,Second; unsignedcharHIGH_ADD,LOW_ADD; //High&LowbyteforEEPROMmemoryaddressbitSM_BUSY; //Thisbitissetwhenasendorreceive //isstarted.Itisclearedbythe //ISRwhentheoperationisfinished.////FunctionPROTOTYPES//voidSMBus_ISR(void); ////MAINRoutine//////MainroutineconfiguresthecrossbarandSMBus,andtests//theSMBusinterfacebetweenthethreeEEPROMsvoidResetRealClock(void){ while(SM_BUSY); //WaitforSMBustobefree. SM_BUSY=1; //OccupySMBus(settobusy) SMB0CN=0x44; //SMBusenabled,ACKonacknowledgecycle BYTE_NUMBER=0; //2addressbytes. COMMAND=(CLOCK3530_ADDRESS_RESET|READ); //Chipselect+READ STA=1; //Starttransfer while(SM_BUSY); //Waitfortransfertofinish}//======================寫S-3530A內(nèi)部實(shí)時(shí)數(shù)據(jù)寄存器程序=====================//功能:將設(shè)定年、月、日、星期、時(shí)、分、秒數(shù)據(jù)寫入S-3530A|//入口:發(fā)送數(shù)據(jù)放在年、月、日、星期、時(shí)、分、秒各寄存器|//出口:NONE|//==========================================================================voidSetRealClock(void){ while(SM_BUSY); //WaitforSMBustobefree. SM_BUSY=1; //OccupySMBus(settobusy) SMB0CN=0x44; //SMBusenabled,ACKonacknowledgecycle BYTE_NUMBER=7; //2addressbytes. COMMAND=(CLOCK3530_ADDRESS_DATEHOUR|WRITE); //Chipselect+WRITE I2CDataBuff=&RealTime.ClockString[0]; //Datatobewriten STA=1; //Starttransfer}//==================讀S-3530A實(shí)時(shí)數(shù)據(jù)寄存器子程序===========================//功能:從S-3530A讀入當(dāng)前時(shí)間數(shù)據(jù)|//入口:NONE|//出口:接收數(shù)據(jù)放在年、月、日、星期、時(shí)、分、秒各寄存器|//==========================================================================voidGetRealClock(void){ while(SM_BUSY); //WaitforSMBustobefree. SM_BUSY=1; //OccupySMBus(settobusy) SMB0CN=0x44; //SMBusenabled,ACKonacknowledgecycle BYTE_NUMBER=7; //2addressbytes. COMMAND=(CLOCK3530_ADDRESS_DATEHOUR|READ); //Chipselect+READ I2CDataBuff=&RealTime.ClockString[0]; //Datatobewriten STA=1; //Starttransfer while(SM_BUSY); //Waitfortransfertofinish}//============================寫狀態(tài)寄存器程序==============================//功能:讀/寫S-3530A狀態(tài)寄存器,對(duì)S-3530A進(jìn)行設(shè)置|//入口:NONE出口:NONE|//==========================================================================unsignedcharGetRealClockStatus(void){ unsignedcharresult; while(SM_BUSY); //WaitforSMBustobefree. SM_BUSY=1; //OccupySMBus(settobusy) SMB0CN=0x44; //SMBusenabled,ACKonacknowledgecycle BYTE_NUMBER=1; COMMAND=(CLOCK3530_ADDRESS_STATUS|READ); I2CDataBuff=&result; STA=1; //Starttransfer while(SM_BUSY); //Waitfortransfertofinish returnresult;}voidSetRealClockStatus(unsignedcharstatus){ while(SM_BUSY); //WaitforSMBustobefree. SM_BUSY=1; //OccupySMBus(settobusy) SMB0CN=0x44; //SMBusenabled,ACKonacknowledgecycle BYTE_NUMBER=1; COMMAND=(CLOCK3530_ADDRESS_STATUS|WRITE); I2CDataBuff=&status; STA=1; //Starttransfer}#include"INTRINS.H"unsignedcharrevolve(unsignedcharval){chari;unsignedcharval1=0; for(i=0;i<8;i++) { if(val&0x1) val1++; val1=_crol_(val1,1); val=_cror_(val,1); } val1=_cror_(val1,1); returnval1;}/*--鄔--*/charcodewu1[]={0x00,0x00,0xFC,0x06,0x45,0x84,0x7E,0x04,0x00,0x00,0xFE,0x42,0xB2,0x0E,0x00,0x00,0x10,0x10,0x13,0x12,0x12,0x1A,0x52,0x82,0x7F,0x02,0xFF,0x10,0x20,0x11,0x0E,0x00,};/*--西--*/charcodexi1[]={0x04,0xC4,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0xE6,0x44,0x00,0x00,0xFF,0x40,0x50,0x48,0x47,0x40,0x40,0x40,0x47,0x48,0x48,0x40,0xFF,0x00,0x00,};/*--占--*/charcodezhan[]={0x00,0x00,0x80,0x80,0x80,0x80,0xFF,0x88,0x88,0x88,0x88,0xC8,0x8C,0x08,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00,};/*--朱--*/charcodezhu[]={0x80,0x80,0xA0,0x9E,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x8C,0x88,0xC0,0x80,0x00,0x20,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,0x02,0x04,0x08,0x08,0x10,0x30,0x10,0x00,};/*--婉--*/charcodewan[]={0x10,0xF0,0x1F,0x10,0xF0,0x10,0x0C,0xF4,0x24,0xE5,0x06,0xE4,0x24,0xF4,0x2C,0x00,0x42,0x35,0x08,0x16,0x21,0x84,0x43,0x24,0x18,0x07,0x00,0x3F,0x42,0x47,0x70,0x00,};/*--整--*/charcodezheng[]={0x00,0x04,0x74,0xD4,0xFF,0xD4,0x74,0x04,0x10,0x0C,0xB7,0x44,0xB4,0x0C,0x04,0x00,0x00,0x42,0x43,0x7A,0x43,0x42,0x43,0x7E,0x4B,0x4B,0x4A,0x4A,0x42,0x43,0x01,0x00,};/*--表情:笑--*/charcodexiao[]={0x00,0x00,0xE0,0x50,0xA8,0xA8,0x48,0x88,0x48,0xA8,0xA8,0x50,0xE0,0x00,0x00,0x00,0x00,0x00,0x07,0x08,0x10,0x10,0x12,0x14,0x12,0x10,0x10,0x08,0x07,0x00,0x00,0x00,};/*--xin--*/charcodexin[]={0x80,0x40,0x20,0xF8,0x07,0x24,0x24,0x24,0x25,0x26,0x24,0x24,0xB4,0x26,0x04,0x00,0x00,0x00,0x00,0xFF,0x00,0x01,0xFD,0x45,0x45,0x45,0x45,0x45,0xFD,0x01,0x00,0x00,};/*--xi--*/charcodexi[]={0x00,0x00,0x00,0xFC,0xA4,0xA6,0xA5,0xA4,0xA4,0xA4,0xA4,0xFE,0x04,0x00,0x00,0x00,0x40,0x30,0x00,0x77,0x84,0x84,0x8C,0x94,0xB4,0x84,0x84,0xE7,0x00,0x10,0x60,0x00,};/*xue*/charcodexue[]={0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00,0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x06,0x04,0x00,};/*yuan*/charcodeyuan[]={0x00,0xFE,0x22,0x5A,0x96,0x0C,0x24,0x24,0x25,0x26,0x24,0x34,0xA4,0x14,0x0C,0x00,0x00,0xFF,0x04,0x08,0x87,0x81,0x41,0x31,0x0F,0x01,0x3F,0x41,0x41,0x41,0x70,0x00,};/*--文字:時(shí)--*/charcodeShi[]={0x00,0xFC,0x84,0x84,0x84,0xFE,0x14,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x23,0x40,0x80,0x7F,0x00,0x00,0x00,};/*--文字:分--*/charcodeFen[]={0x00,0x80,0x40,0x20,0x98,0x86,0x80,0x80,0x83,0x8C,0x90,0x20,0xC0,0x80,0x80,0x00,0x01,0x00,0x80,0x40,0x20,0x1F,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x01,0x00,0x00,};/*--文字:秒--*/charcodeMiao[]={0x20,0x24,0x24,0xA4,0xFE,0xA3,0x22,0x80,0x70,0x00,0xFF,0x00,0x10,0x20,0x60,0x00,0x10,0x08,0x06,0x01,0xFF,0x00,0x81,0x80,0x40,0x20,0x17,0x08,0x04,0x03,0x00,0x00,};/*--文字:年--*/charcodeNian[]={0x00,0x20,0x10,0xCC,0x47,0x44,0x44,0xFC,0x44,0x44,0x44,0x64,0x46,0x04,0x00,0x00,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,};/*--文字:月--*/charcodeYue[]={0x00,0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0xFF,0x02,0x00,0x00,0x00,0x00,0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,0x00,};/*--文字:日--*/charcodeRi[]={0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFF,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00,0x00,};/*--文字:表--*/charcodebiao[]={0x80,0x84,0x94,0x94,0x94,0x94,0x94,0xFF,0x94,0x94,0x94,0x94,0x96,0xC4,0x80,0x00,0x10,0x10,0x08,0x08,0x04,0xFE,0x41,0x22,0x04,0x08,0x14,0x12,0x20,0x60,0x20,0x00,};/*--文字:空白--*/charcodewu[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*--fansekongbai--*/charcodekong[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,};/*--文字:設(shè)--*/charcodeshe[]={0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9F,0x81,0x81,0x81,0x9F,0xA0,0x20,0x20,0x00,0x00,0x00,0x00,0x7F,0xA0,0x90,0x40,0x43,0x2C,0x10,0x28,0x26,0x41,0xC0,0x40,0x00,};/*--文字:置--*/charcodezhi[]={0x00,0x10,0x17,0xD5,0x55,0x57,0x55,0x7D,0x55,0x57,0x55,0xD5,0x17,0x10,0x00,0x00,0x40,0x40,0x40,0x7F,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x7F,0x40,0x60,0x40,0x00,};/*--文字:期--*/charcodeqi[]={0x00,0x08,0xFF,0xA8,0xA8,0xA8,0xFF,0x08,0x00,0xFE,0x22,0x22,0x22,0xFF,0x02,0x00,0x84,0x44,0x37,0x04,0x04,0x14,0xA7,0x44,0x24,0x1F,0x02,0x42,0x82,0x7F,0x00,0x00,};/*--時(shí)間--*/charcodetime[]={0xFF,0xFF,0x0F,0xF7,0xFB,0xFB,0xFB,0x0B,0x7B,0x7B,0x7B,0x77,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0xF7,0xEB,0xED,0xEE,0xEF,0xEF,0xEF,0xEF,0xF7,0xF8,0xFF,0xFF,0xFF,};/*--文字:鬧--*/charcodenao[]={ 0x00,0x00,0xF9,0x12,0x90,0x92,0x96,0xFA,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00, 0x00,0x00,0xFF,0x00,0x1F,0x00,0x00,0x7F,0x00,0x08,0x1F,0x40,0x80,0x7F,0x00,0x00,};/*--文字:鈴--*/charcodeling[]={ 0x40,0x30,0x2C,0xEB,0x28,0x28,0x40,0x20,0x18,0x27,0xC8,0x10,0x20,0x60,0x20,0x00, 0x01,0x01,0x01,0xFF,0x41,0x21,0x00,0x01,0x09,0x11,0xE9,0x45,0x03,0x01,0x00,0x00,};/*--文字:星--*/charcodexing[]={0x00,0x00,0xBE,0x2A,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0xBF,0x02,0x00,0x00,0x48,0x44,0x4B,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x4D,0x49,0x61,0x40,0x00,};/*--文字:一--*/charcodeYi[]={ 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*--文字:二--*/charcodeEr[]={ 0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00,0x00, 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00,};/*--文字:三--*/charcodeSan[]={ 0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00, 0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,};/*--文字:四--*/charcodeSi[]={ 0x00,0xFE,0x02,0x02,0x02,0xFE,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0xFE,0x00,0x00, 0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x22,0x7F,0x00,0x00,};/*--文字:五--*/charcodeW[]={ 0x00,0x02,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0xC2,0x82,0x02,0x00,0x00,0x00, 0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x30,0x20,0x00,};/*--文字:六--*/charcodeLiu[]={ 0x10,0x10,0x10,0x10,0x10,0x91,0x12,0x1E,0x94,0x10,0x10,0x10,0x10,0x10,0x10,0x00, 0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x00,0x00,0x01,0x02,0x0C,0x78,0x30,0x00,0x00,};/*--文字:周--*/charcodeZhou[]={ 0x00,0x00,0x00,0xFE,0x02,0x42,0x4A,0x4A,0x7E,0x4A,0x4A,0x42,0x02,0xFE,0x00,0x00, 0x80,0x40,0x30,0x0F,0x00,0x00,0x1F,0x09,0x09,0x09,0x1F,0x40,0x80,0x7F,0x00,0x00,};/*--文字:開--*/charcodekai[]={ 0x7F,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7C,0x3D,0x7F,0xFF,0xFF,0x7F,0xBF,0xCF,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,};/*--文字:關(guān)--*/charcodeguan[]={0x00,0x10,0x10,0x11,0x12,0x1C,0x10,0xF0,0x10,0x18,0x14,0x13,0x1A,0x90,0x00,0x00,0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x21,0x41,0xC1,0x41,0x00,};/*fuhao*/charcodezhong[]={0x00,0x00,0xF0,0x08,0x04,0x04,0x14,0xFC,0x14,0x04,0x84,0x08,0xF0,0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x20,0x21,0x21,0x21,0x23,0x11,0x0F,0x00,0x00,0x00,};/*yue*/charcodeyin[]={0x00,0x18,0x24,0xC4,0x24,0x14,0x08,0x28,0xF8,0x28,0x08,0x94,0x24,0xC4,0x24,0x18,0x00,0x00,0x00,0x07,0x08,0x10,0x20,0x20,0x21,0x21,0x21,0x13,0x09,0x07,0x00,0x00,};/*--文字:點(diǎn)--*/charcodedian[]={ 0x00,0x00,0xC0,0x40,0x40,0x40,0x7F,0x48,0x48,0x48,0x48,0xE8,0x4C,0x08,0x00,0x00,0x80,0x40,0x37,0x04,0x14,0x64,0x04,0x14,0x24,0x64,0x04,0x17,0x20,0xC0,0x00,0x00,};voidLCD_WriteHZ(charx,chary,char*Dot);voidLCD_DispChar(charx,chary,charch);//128*64取值x=0-128y=0-8void InitLCD(void);voidDelay1ms(unsignedcharT);voidTestI2C(void){ unsignedcharvar; WDTCN=0xde; //disablewatchdogtimer WDTCN=0xad; OSCICN|=0x03; //Setinternaloscillatortohighestsetting P0MDOUT|=0x1D; SMB0CN=0x44; //EnableSMBuswithACKsonacknowledgecycle SMB0CR=-80; //SMBusclockrate=100kHz. EIE1|=2; //SMBusinterruptenable EA=1; //Globalinterruptenable SM_BUSY=0; //FreeSMBusforfirsttransfer. var=GetRealClockStatus(); ResetRealClock(); var=GetRealClockStatus(); SetRealClockStatus(0xc2); var=GetRealClockStatus(); GetRealClock(); RealTime.RT.Year=0x05; RealTime.RT.Month=0x01; RealTime.RT.Day=0x01; RealTime.RT.Week=0x06; RealTime.RT.Hour=0x00; RealTime.RT.Minute=0x00; RealTime.RT.Second=0x00; SetRealClock(); GetRealClock(); LCD_WriteHZ(32,4,wu);LCD_WriteHZ(64,4,wu);LCD_WriteHZ(96,4,wu);LCD_WriteHZ(32,2,wu); LCD_WriteHZ(64,2,wu); LCD_WriteHZ(96,2,wu); LCD_WriteHZ(64,0,wu); LCD_WriteHZ(80,0,wu);LCD_WriteHZ(0,0,wu); LCD_WriteHZ(112,0,wu); LCD_WriteHZ(112,2,wu); LCD_WriteHZ(112,4,wu); LCD_WriteHZ(0,6,wu);LCD_WriteHZ(16,6,wu);LCD_WriteHZ(32,6,wu);LCD_WriteHZ(112,6,wu);LCD_WriteHZ(16,0,xiao);LCD_WriteHZ(32,0,xin);LCD_WriteHZ(48,0,xi);LCD_WriteHZ(64,0,xue);LCD_WriteHZ(80,0,yuan);LCD_WriteHZ(96,0,xiao);LCD_DispChar(0,2,1);LCD_DispChar(8,2,2);LCD_DispChar(16,2,3);LCD_DispChar(24,2,0);LCD_DispChar(32,2,4);LCD_DispChar(40,2,0);LCD_DispChar(48,2,0);LCD_DispChar(56,2,3);LCD_DispChar(64,2,6);LCD_WriteHZ(80,2,wu1);LCD_WriteHZ(96,2,xi1);LCD_WriteHZ(112,2,zhan);LCD_DispChar(0,4,1);LCD_DispChar(8,4,2);LCD_DispChar(16,4,3);LCD_DispChar(24,4,0);LCD_DispChar(32,4,4);LCD_DispChar(40,4,0);LCD_DispChar(48,4,0);LCD_DispChar(56,4,2);LCD_DispChar(64,4,1);LCD_WriteHZ(80,4,zhu);LCD_WriteHZ(96,4,wan);LCD_WriteHZ(112,4,wan);for(i=0;i<=30;i++)Delay1ms(500);InitLCD(); //在0,4處顯示00時(shí)00分00秒//LCD_DispChar(0,4,time); LCD_DispChar(16,4,0);//128*64取值x=0-128y=0-8 LCD_DispChar(24,4,0); LCD_WriteHZ(32,4,Shi); LCD_DispChar(48,4,0); LCD_DispChar(56,4,0); LCD_WriteHZ(64,4,Fen); LCD_DispChar(80,4,0); LCD_DispChar(88,4,0); LCD_WriteHZ(96,4,Miao); //在0,2處顯示2000年01月01日//LCD_DispChar(0,2,2);//LCD_DispChar(8,2,0); LCD_DispChar(16,2,1);//128*64取值x=0-128y=0-8 LCD_DispChar(24,2,2); LCD_WriteHZ(32,2,Nian); LCD_DispChar(48,2,0); LCD_DispChar(56,2,7); LCD_WriteHZ(64,2,Yue); LCD_DispChar(80,2,0); LCD_DispChar(88,2,9); LCD_WriteHZ(96,2,Ri); LCD_WriteHZ(64,0,xing); LCD_WriteHZ(80,0,qi); LCD_WriteHZ(96,0,Yi); LCD_WriteHZ(112,0,nao); LCD_WriteHZ(112,2,ling); LCD_WriteHZ(112,4,guan);LCD_WriteHZ(2,6,zhong);LCD_WriteHZ(112,6,yin); for(;;) { GetRealClock(); if(K1==0)Delay1ms(500); if(K1==0)n++; if(n==1) { Year=RealTime.RT.Year; Month=RealTime.RT.Month; Day=RealTime.RT.Day; Week=RealTime.RT.Week; Minute=RealTime.RT.Minute; Second=RealTime.RT.Second; LCD_WriteHZ(0,0,she); LCD_WriteHZ(16,0,zhi);

溫馨提示

  • 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)論