【正文】
x5=1。yue=read_1302(0x89)。x6=ri/16。x6=0。write_(0x80+4)。x7=nian%16。x6=0。write_(0x80+0x40+8)。x3=fen%16。x1++。這一功能是如何實(shí)現(xiàn)的呢?首先判斷是平年還是閏年,本時鐘的年調(diào)節(jié)區(qū)間為 2022 年-2079 年。write_1302(0x8e,0x80)。write_(0x0f)。write_1302(0x8c,nian)。write_(0x80+0x40+5)。}if(s1num==2)//如果 S1 按下兩次,先將設(shè)置后的秒寫到 DS1302,再在分的個位位置閃爍光標(biāo){ write_1302(0x8e,0x00)。//按鍵次數(shù)清 0}}} 功能鍵函數(shù)if(s1==0amp。}if(ap1!=0amp。amp。0x1f。hour=read_1302(0x85)。ge==2){hour=0xb0。}if(shi==2amp。hour=hour+0x20。amp。if(s2num==1)//24 小時切換成 12 小時{int ge,shi。然后提取其后 5 位時間,顯示時間。第一次按下切換鍵,把瞬時時間轉(zhuǎn)化成 12 小時制,令 flag1=1。//定義顯示在液晶的什么位置write_data(0x30+shi)。num8。//開顯示、不顯示光標(biāo)write_(0x06)。delay(5)。 //將要寫的指令賦給 P0 口,delay(5)。return(temp)。//每次傳輸?shù)妥止?jié),等價于 temp=temp|0x80sck=0。} 從 DS1302 讀數(shù)據(jù)/***************************讀 DS1302 數(shù)據(jù)函數(shù)*************************/uchar read_1302(uchar add)//輸入地址 add,返回讀取的數(shù)據(jù){uchar i,temp=0x00。_nop_()。for(i=0。y)。采用 DS1302 時鐘芯片的單片機(jī)時鐘,其實(shí)質(zhì)就是讀取時鐘芯片內(nèi)的時鐘信息并把它顯示出來。XXXX1110 ⑺ 。第 6 腳:E 端為使能端,當(dāng) E 端由高電平跳變成低電平時,液晶模塊執(zhí)行命令。2. 3 1602 字符液晶介紹 1602 液晶概述工業(yè)字符型液晶,1602 是指顯示的內(nèi)容為 16*2,能同時顯示兩行,每行 16個字符。當(dāng)“WP”為 1 時,寫保護(hù)位防止對任一寄存器的寫操作。SCLK:串行時鐘輸入端,控制數(shù)據(jù)的輸入與輸出I/O: 三線接口時的雙向數(shù)據(jù)線 CE: 輸入信號,在讀、寫數(shù)據(jù)期間必須為高 DS1302 使用方法(1) 時鐘芯片 DS1302 的工作原理: DS1302 在每次進(jìn)行讀、寫程序前都必須初始化,先把 SCLK 端置 “0”,接著把 RST 端置“1”,最后才給予 SCLK 脈沖;讀/ 寫時序如圖 5 所示。兩個小電容通常取值 3pF,以保證振蕩器電路的穩(wěn)定性及快速性。④可編程輸入/輸出引腳(32 根)STC89C52 單片機(jī)有 4 組 8 位的可編程 I/O 口,分別位 P0、P1 、PP3 口,每個口有 8 位(8 根引腳),共 32 根。采用此種方案雖然減少芯片的使用,節(jié)約成本,但是,實(shí)現(xiàn)的時間誤差較大。 顯示模塊選擇方案和論證方案一:采用點(diǎn)陣式數(shù)碼管顯示。研究目的通過利用 STC89C52 單片機(jī)和 DS1302 芯片以及外圍的按鍵和 LCD 顯示器等部件,設(shè)計一個基于單片機(jī)的電子時鐘。關(guān)鍵詞:單片機(jī),電子時鐘,STC89C52 ABSTRACTWith the rapid development of microputer technology in its promotion, modern electronics into almost all areas of society, a strong impetus to the development of social productive forces and social improvement in the level of information, but also to further improve the performance of modern electronic products.Time is a money, time is life, time is victory… Accurate grasp of time and allocation of time is crucial to people, The clock is necessary in our life tools . Clock Design There are many ways, however, produced by single chip electronic clock is more flexible programming, and easy expansion of electronic capabilities, high accuracy, easy to carry, display visual and so on. In this paper, through the use of STC89C52 microcontroller by DS1302 clock chips for reading and writing operation and through 1602 character liquid crystal display realtime clock information so that forming a single chip electronic clock. Key Words: Microcontroller,STC89C52 ,Electronic clock, 目錄緒論 ...................................................................................................................................1概述 ............................................................................................................................1研究目的 ....................................................................................................................1第 1 章 設(shè)計要求與方案論證 .........................................................................................2 設(shè)計要求 .............................................................................................................2 系統(tǒng)基本方案選擇和論證 .................................................................................2 單片機(jī)芯片的選擇方案和論證 .......................................................................2 顯示模塊選擇方案和論證 ..............................................................................2 時鐘芯片的選擇方案和論證 ..........................................................................3 電路設(shè)計最終方案決定 ....................................................................................3第 2 章 主要元件介紹 .....................................................................................................4 STC89C52 介紹 ................................................................................................4 STC89C52 主要功能及 PDIP 封裝 ................................................................4 STC89C52 引腳介紹 ....................................................................................4 STC89C52 最小系統(tǒng) ....................................................................................5 DS1302 時鐘芯片介紹 .....................................................................................6 DS1302 概述 ...............................................................................................6 DS1302 引腳介紹 .........................................................................................7 DS1302 使用方法 ........................................................................................72. 3 1602 字符液晶介紹 .........................................................................................9 1602 液晶概述 .............................................................................................9 1602 引腳介紹 .............................................................................................10 1602 字符液晶使用方法 .............................................................................10第 3 章 系統(tǒng)硬件設(shè)計 ...................................................................................................13 電路設(shè)計框圖 ...................................................................................................13 系統(tǒng)硬件概述 ...................................................................................................13第 4 章 系統(tǒng)的軟件設(shè)計 ...............................................................................................14 程序概述 ......................................................................................