![[單片機]c51數(shù)字時鐘(帶年月日顯示)_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-5/27/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de0531/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de05311.gif)
![[單片機]c51數(shù)字時鐘(帶年月日顯示)_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-5/27/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de0531/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de05312.gif)
![[單片機]c51數(shù)字時鐘(帶年月日顯示)_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-5/27/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de0531/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de05313.gif)
![[單片機]c51數(shù)字時鐘(帶年月日顯示)_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-5/27/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de0531/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de05314.gif)
![[單片機]c51數(shù)字時鐘(帶年月日顯示)_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-5/27/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de0531/0e6c0bc1-890a-4b8f-b0e3-7c8ab5de05315.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、【單片機】c51數(shù)字時鐘(帶年月日顯 示)00%8-3H 一 -hli.lljLiJInIQ. c V UM. B戸rr:館 靈;-丄-S:T顯示當前時間:9點58分34秒(第一個零表示鬧鐘未開啟)冃 000 0030. TJ - TJ *IJ當前日期:10年4月六日摘要:本設(shè)計以單片機為核心,LED數(shù)碼管動態(tài)掃描顯示。采用矩陣式鍵盤輸入 能任意修改當前時間日期和設(shè)定鬧鐘時間。 具有顯示年月日(區(qū)分閏年和二月) 鬧鐘報警和整點報時功能說明系統(tǒng)的功能選擇由7個按鍵完成。其中P3.0,P3.1分別對應調(diào)整當前時間的時和分,P3.2為外部中斷0,控制鬧鐘功能的開啟/關(guān)閉(開啟時數(shù)碼管第一位顯示字母
2、c)P3.3用作外部中斷1,當前時間的顯示與鬧鈴時間顯示切換,鬧鐘顯示時按 P3.0,P3.1可進行鬧鐘時分的設(shè)定,此時,ledl燈滅。鬧鈴時間到切鬧鐘開關(guān)開 啟時,鬧鈴響一分鐘。P3.5P3.6P3.7對年月日進行調(diào)整(第一次按P3.5,就進入了年月日的顯示,現(xiàn) 在就可對日期進行調(diào)整)。按 P3.1回到當前時間的顯示狀態(tài)。整點到時:報警對應小時的次數(shù)。程序如下:#in clude#i nclude#i nclude#defi ne uchar un sig ned char#defi ne uint un sig ned intuchar data keyvalue;/ 查到的鍵值uchar
3、 data keys;/轉(zhuǎn)換出的數(shù)字uchar dis8;uchar codeSeg=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67,0x40,0x00,0x39,0xf7;56sbit led_dua n=P2W;sbit led_wei=P2A7;sbit speaker=P2A3;sbit mini tek=P3A0;sbit hourk=P3A1;sbit p3_4=P3A4;sbit yeark=P3A5;sbit mon thk=P3A6;sbit dayk=P3A7;/ 0789-/段選通/位選通/蜂鳴器/分校正按鍵/小時校正按
4、鍵/年/月/日123滅燈 c nbit leap_year;bit dis_ nyr;bit cal_year=1;bit calculate=1; uchar data c_mi n; uchar data c_hou;/閏年標志位uchar data wei,i;/顯示年月日與當前時間切換標志/鬧鐘分寄存單元/鬧鐘、小時寄存單元uchar data second;/ 秒uchar data minite;/ 分變量uchar data hour;/ 小時變量uchar data year,m on th,day; uchar data CNTA;uchar data speaker, nu
5、m; bit beep;bit r un;bit flash;bit clarm_switch;bit baoshi;sbit led仁 P1A6;sbit led2=P1A7;sbit P3_2=P3A2;sbit P3_3=P3A3; uint n,k;/*10微秒級延時*/ void delay_10us(uchar n) do _nop_();_nop_();_nop_();_nop_();_nop_();while(-n);/*毫秒級延時*/定義年月日變量/蜂鳴次數(shù)/整點報時標志/運行標志/滅燈標志/鬧鐘開關(guān)標志/報時開關(guān)標志/按鍵標識指示燈/運行標志指示燈void delay_ms
6、( uint n) do delay_10us(131);while(-n);/*當前時間轉(zhuǎn)換*/clk_to_dis()dis0=seco nd%10;dis1=seco nd/10; if(flash)dis2=10;else dis2=11;dis3=mi nite%10;dis4=mi nite/10;dis 5=hour%10;dis6=hour/10;/*定時鬧鐘顯示譯碼(用于七段碼顯示)*/clarm_to_dis() 一一disO=c_mi n%10;dis1=c_mi n/10;if(flash)dis2=10;/ 亮燈/滅燈else dis2=11;dis3=c_hou%1
7、0;dis4=c_hou/10;dis5=10;dis 6=13; 年月日顯示譯碼*ny r_to_dis() 一一dis0=day%10;dis1=day/10;dis2=10;/ 顯示 -dis3=mo nth%10;dis4=m on th/10;dis5=10;/ -dis6=year%10;dis7=year/10;/*主函數(shù)*/void mai n()P2=0xff;P仁 0XFF;p3_4=0;run=1;led2=0;/運行指示燈亮led仁1;flash=0x00;dis2=10;/第三位顯示“wei=0x7f; /選通低位i=0;second=21;min ite=58;ho
8、ur=9;CNTA=0x00;year=10;mon th=4;day=5;clk_to_dis();TMOD=Ox11;TH0=15560/256;TL0=15560%256;TH1=0xfc;TL1=0x18;EA=1;PT0=1;EX0=1;/開中斷;EX仁1;ET0=1;ET1=1;TR0=1;TR1=1;while(1)while(r un=1) clk_to_dis();if(calculate)if(mon th=1|m on th=3|m on th=5|m on th=7|m on th=8|m on th=10| mont h=12)day+;if(day31)day=0x
9、01;mo nth+;if(mon th=13)m on th=1;year+;cal_year=1;led仁0;/指示燈亮if(mon th=4 |mon th=6|m on th=9|m on th=11)day+;if(day30)day=0x01;mo nth+;led仁0;/指示燈亮if(mon th=2) if(leap_year=1)day+;if(day=30)day=1;else day+;if(day=29)day=1;while(cal_year) _if(yea葉2000)%400=0) leap_year=1;/ 被 400 整除為閏年else if(yea葉2000
10、)%100=0) leap_year=0; / 不能 被400整除 能被100整除 不是閏年elseif(yea葉2000)%4=0)leap_year=1; / 不能被 400、100 整除能被 4整除是閏年else leap_year=0;cal_year=0; _calculate=0;led1=1;while(!mi nitek)for(n=0; n1000; n+);if(!minitek=0)break;/ 延時防抖min ite+;second=0x00;led 仁0;for(n=0;n 20; n+)speaker=!speaker; delay_10us(50);/ 蜂鳴器響
11、if(mi nite=60)mi ni te=0x00;while(!minitek);/ 等待鍵松開led1=1;/顯示燈while(!hourk)for(n=0 ;n 1000; n+); if(!hourk=0)break; hour+;second=0x00;led 仁0;/蜂鳴器響for(n=0; n30; n+) speaker=!speaker; delay_10us(30); _if(hour=24) hour=0x00; while(!hourk);led 1=1;while(!yeark)/yeark鍵復用進入年月日調(diào)整for(n=0; n1000; n+);if(!yea
12、rk=O)break;dis_ ny r=1;while(!yeark);while(dis_ nyr) nyr_to_dis();while(!yeark)for(n=0;n 1000; n+);if(!yeark=0)break;year+;led 仁0;for(n=0; n 30; n+)speaker=!speaker;delay_10us(30);/ 蜂鳴器響if(year+2000)%400=0) leap_year=1;/ 被400整除為閏年else if(yea葉2000)%100=0) leap_year=0;/不能被400整除 能被100整除 不是閏年elseif(yea葉
13、2000)%4=0)leap_year=1; / 不能被 400、100 整除能被 4整除是閏年else leap_year=0;while(!yeark);led仁1;while(!m on thk)for(n=0;n 1000; n+);if(!m on thk=0)break;mon th+;if(mon th=13)m on th=1;led 仁0;for(n=0; n 30; n+)speaker=!speaker;delay_10us(30);/ 蜂鳴器響while(!m on thk);led仁1;while(!dayk)for(n=0;n 31)day=0x01;led仁0;/
14、指示燈亮if(mon th=4 |mon th=6|m on th=9|m on th=11)day+;if(day30)day=0x01;led仁0;/指示燈亮if(mon th=2) if(leap_year=1)day+;if(day=30)day=1;else day+;if(day=29)day=1;led 仁0;for(n=0; n 30; n+)speaker=!speaker;delay_10us(30);/ 蜂鳴器響while(!dayk);led仁1;while(!hourk) for(n=0; n1000; n+);if(hourk) break;dis_ nyr=0;w
15、hile(!hourk);if(clarm_switch)dis7=12;/ 開啟顯示Celse dis7=11;/ 關(guān)閉 不顯示dis 6=11;clk_to_dis(); if(clarm_switch)/鬧鈴時間到,指示燈閃爍 蜂鳴器長響if(c_m in=min ite&c_hou=hour)speaker, num=60;beep=1;while(beep& clarm_switch) _led仁!Ied1;delay_ms(100);clk_to_dis(); 一一led仁1;beep=0;while(run=0)/鬧鐘時間設(shè)定 clarm_to_dis();/while(!mi
16、nitek)for(n=0; n1000; n+);if(!minitek=0)break;/ 延時防抖c_mi n+;led 仁0;for(n=0;n 20; n+)speaker=!speaker; delay_10us(50);/ 蜂鳴器響if(c_m in=60)c_m in=0x00;while(!minitek);/ 等待鍵松開led1=1;/顯示燈while(!hourk)for(n=0; n1000; n+);if(!hourk=0)break;c_hou+;led 仁0;for(n=0; n7)speaker_num=2*hour;/ 整點到設(shè)定報時次數(shù) 蜂鳴標志 置1bee
17、p=1;if(hour=24)hour=0; calculate*110點到,日期標志加一TR 1=1;定時器中斷 T1*/timer1() in terrupt 3 using 3 TH1=0xfc;TL1=0x18;P0=0xff; led_wei=1; led_wei=0;P0=segdisi;led_dua n=1;led_dua n=0;P0=wei; led_wei=1;led_wei=0; if(+i=8)i=0; wei=_cror_(wei,1);外中斷int_0() in terrupt 0/鬧鐘開關(guān)/開啟顯示/關(guān)閉不顯示 開啟第一位顯示Cclarm_switch=!clarm_sw
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 專業(yè)土地抵押合同
- 工程建設(shè)合同協(xié)議書
- 保潔服務(wù)合同和內(nèi)容
- 在建工程抵押反擔保合同
- 擔保人合同擔保合同
- 企業(yè)軟件銷售合同
- 場地門面出租合同
- 人工智能在醫(yī)療影像領(lǐng)域的應用合同
- 測繪工程部技術(shù)員聘用合同
- 湖北恩施學院《學前兒童發(fā)展科學》2023-2024學年第二學期期末試卷
- 放射診療設(shè)備清單
- 供應鏈中的社會責任
- HDPE纏繞-B型結(jié)構(gòu)壁管施工方案
- 汽車發(fā)動機構(gòu)造與維修中職PPT完整全套教學課件
- 養(yǎng)老院管理-考核考評
- 人美版四年級書法下冊《第6課 豎心旁》教學設(shè)計
- 二年級綜合實踐活動課件-我與蔬菜交朋友-全國通(41張)
- 血型與輸血檢驗-臨床輸血(臨床檢驗課件)
- 按摩師培訓協(xié)議書
- 落地式腳手架安全技術(shù)措施
- 開心麻花《白蛇前傳》劇本
評論
0/150
提交評論