


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、功能描述:产品可以显示时间和日期,时间格式为 hh mm ss 日期格式 为 时间和日期轮流显示。 时间显示 5S 日期显示 3S。可以设置 5 个闹铃,闹铃音乐可以设置 两种:毛驴和童年。三个按键对时间和闹铃进行设置,六 个LED进行显示。计时采用DS1307继电时间不丢失, 设置过的闹铃也不丢失。闹铃音乐由单片机的两个定时器去产生 频率实现。部分程序如下:/*/* /*/程序名:DS1307时钟程序/ 功能描述:用六个八段 LED 轮流显示时间/和日期。有6个闹钟。上电时从DS1307中读出/当前时间、日期、闹钟。/#include <reg52.h>#include <
2、intrins.h>#define uchar unsigned char#define uint unsigned int #define LED P2#define LEDBit P0#define nop _nop_(>#define LightCount 40#define LightMax 80sbit SCL=P3A1 。sbit SDA=P3A0。sbit ModeKey=P1A0 。sbit UpKey=P1A1 。sbit DownKey=P1A2 。sbit Speak=P3A6 。code ucharLCD_NUM10=0x03,0x9f,0x25,0x0d,
3、0x99,0x49,0x41,0x1f,0x01,0x09。/0x25,/uchar Clock=0x88,0x88,0x88。codeuint Music_Sound_Long1=4,8,4,8,8,4,8,4,4,4,/* 童年 */8,4,8,4,4,4,4,4,16,4,4,8,4,4,4,4,4,8,4,4,4,8,4,4,4,4,4,4,16,4,4,8,4,4,4,4,4,8,4,4,4,8,4,4,4,4,4,4,16,4,8,4,8,4,4,4,8,8,4,4,4,4,4,4,4,4,4,4,4,16,4,8,4,8,8,4,8,4,4,4,8,4,8,4,4,4,4,4,1
4、6,4,8,4,8,8,4,8,4,4,4,8,4,8,4,4,4,4,4,16,0, Music_Sound_Long2=4,4,4,4,4,4,4,4,4,4,/* 小毛驴 */4,4,16,4,4,4,4,4,4 ,4,4,4,4,4,4,8,4,4,4,4,4,4,4,4,4,4,4,4,4,16,4,4,4,4,2,2,2,2,4,4, 4,4,4,4,16,0,Music_Sound_Tone1=379,379,379,379,425,477,477,477,425,477, 568,637,637,637,568,637,425,379,477,719, 637,637,719,
5、637,568,568,506,568,568,568,637,477,477,477,477,568,477,568,637,719,637,637,719,637,568,568,506,568,568,568,637,477,477,477,477,568,568,477,851,318,318,318,318,379,425,477,477,568,477,568,477,425,425,425,425,425,477,379,425,425,379,379,379,379,425,477,477,477,425,477,568,637,637,637,568,637,425,379,
6、477,379,379,379,379,425,477,477,477,425,477,568,637,637,637,568,637,425,379,477,0, /* 童年*/Music_Sound_Tone2=956,956,956,719,637,637,637,637,568,568,/* 小毛驴 */568,477,637,716,716,716,568,719,719,719,719,851,851,851,851,637,637,956,956,956,719,637,637,637,637,568,568,568,477,637,716,716,716,568,719,719
7、,719,719,719,719,851,851,851,719,956,0 。uchar DS130727=0 。/00 为秒, 01为分, 02 为时/10 为日, 11为月, 12 为年/20 为闹钟控制, 21为分, 22 为时 /30 为闹钟控制, 31为分, 32 为时 /40 为闹钟控制, 41 为分, 42 为时 / 同上/ 同上/ 闹钟控制十位为闹钟数/ 闹钟控制个位为选择闹钟声音程序/ 个位为零关闭闹钟uchar DisplayArr83=0 。/*void Beep(void> 。void DiplayClock(uchar *>/void UsuaDisPl
8、ay(uchar *> void Delay(uint Count> 。 void DiplayDelay(void> 。void Start(void> void Stop(void>void ack(bit> bit cack(void> 。void Send8bit(unsigned char> 。 / 高字节位先传 字节最低位 1 为读, 0 为写unsigned char Read8bit(void> 。void SendWord(unsigned char,unsigned char> unsigned char Read
9、Word(unsigned char> 。void ReadDS1307(uchar> 。/* void ModeButten(void> 。 void UpButten(void> 。 void DownButten(void> 。/*/ 函数名: INC/ 功能:加 1 函数 void INC(void> 。unsigned char Inc(uchar> 。 unsigned char Dec(uchar> 。void Ring(void> 。uchar Mode=0。Mode=0轻按UP Down为查看时间、日期、闹钟/Mode =
10、 1uchar Read=0 。uchar Juge=0 。/Read=1 为读 DS1307/ 闪烁位数uchar DisplyMode 。uchar Light 。uchar Black 。uchar DisplayLoop 。 uchar RingFlag 。uchar Sound_Long_Count。 uint Period 。断音乐频率中*/*void Music_Tone(>interrupt 3 using 2 Speak=!Speak。TL1=(65536-Period>&0xff 。TH1=(65536-Period>>>8。TF1=0
11、。10ms 中断变void Music_Long(>interrupt 1 using 3 if(Sound_Long_Count!=0>Sound_Long_Count- 。 TL0=(65536-10000>&0xff 。TH0=(65536-10000>>>8。TF0=0。/* TL2=(65536-10000>&0xff 。TH2=(65536-10000>>>8。TF2=0。*/*main(>uchar i,j,Loop 。uchar RingMinBuffer 。uchar RingHouBuffer
12、 。uchar RingMinBufferOld=0xff 。 uchar RingTimeLong 。/* 置定时器初值 */TMOD=Ox1。/*开定时器0,工作在方式3模式下*/TH0=TL0=0x6。TL0=(65536-10000>&0xff 。TH0=(65536-10000>>>8。IE=0xca。/* 允许定时器中断 */ET2=1。/*for(i=0 。 i<6 。 i+>Stop(> 。Start(> 。Send8bit(0xD0> 。 if(cack(>=1>continue 。 Send8bit(
13、0x08+i*0x03> 。if(cack(>=1>continue 。Send8bit(i*0x10+0x10> 。if(cack(>=1>continue 。Stop(> 。*/ReadDS1307(26>。for(DisplyMode=0 。 DisplyMode<8。 DisplyMode+>INC(> 。DisplyMode=0。ReadDS1307(26>。for(i=0,Loop=0 。 i<8 。 i+> for(j=0 。 j<3 。 j+,Loop+>if(Loop=3>L
14、oop+ 。 if(Loop=7>Loop+ 。DisplayArrij=DS1307Loop 。for(i=2 。 i<8 。 i+> for(j=0 。 j<3 。 j+> switch(j>case/ 分钟0: DisplayArrij&=0x73 。 break 。/ 开关闹钟case 1:DisplayArrij&=0x7F。 break 。case 2:DisplayArrij&=0x3F。 break 。DisplayArr10&=0x3F 。/ 日期DisplayArr11&=0x1F 。/ 月份Spe
15、ak=0。 while(1>/DisplayClock(6,Clock>/DiplayClock(Clock> 。/ DiplayClock(DisplayArrDisplyMode>/Juge=1 。DiplayClock(DisplayArrDisplyMode> /* 1/ 读出的数存入单片机中,if(Read=1>ReadDS1307(26>。Read=0。else ReadDS1307(6>。DiplayClock(DisplayArrDisplyMode> 。for(i=0,Loop=0 。 i<8 。 i+> fo
16、r(j=0 。 j<3 。 j+,Loop+>if(Loop=3>Loop+ 。 if(Loop=7>Loop+ 。DisplayArrij=DS1307LoopDiplayClock(DisplayArrDisplyMode>/*111/*222/ 读出的数格式化i+>。 j<3 。 j+>for(i=2 。 i<8for(j=0switch(j> 0: DisplayArrij&=0x73case 1:case 2:default :。breakDisplayArrij&=0x7FDisplayArrij&
17、=0x3Fcase/ 开关闹钟break 。break 。/ 分钟DiplayClock(DisplayArrDisplyMode>DiplayClock(DisplayArrDisplyMode>DisplayArr10&=0x3F 。 / 日期DisplayArr11&=0x1F 。 / 月份*222DiplayClock(DisplayArrDisplyMode>/Beep(>。ModeButten(> 。DownButten(>。UpButten(> 。DiplayClock(DisplayArrDisplyMode>*3
18、33if(Juge=0>/ 日期时间交替显示程序DisplayLoop+ 。 if(DisplayLoop>10>DisplyMode=0 。 if(DisplayLoop>60>DisplyMode=1 。DisplayLoop=0 。 /*33/ 闹钟程序比较0F=0>continue 。*444if(Juge=0>for(i=2 o i<8。 i+>DiplayClock(DisplayArrDisplyMode> 。if(DisplayArri0&0xif(DisplayArri1!=DisplayArr01>c
19、ontinueRingMinBuffer=DisplayArri1if(RingMinBufferOld=RingMinBuffer>continueif(DisplayArri2!=DisplayArr02>continueoif(RingFlag=0>RingMinBuff erOld=0xff oRingFlag=DisplayArri0&0x0FModeButten(> 。DownButten(> 。UpButten(> 。DiplayClock(DisplayArrDisplyMode> 。RingTimeLong=0。switch
20、(RingFlag>case 1:DisplyMode=0 。i=0 。while(Di splayArr01=RingMinBuffer> /* 是否响闹铃 1 程序 */* if(DisplayArr01!=RingMinBuffer>RingMinBuffer=DisplayArr01 。 RingTimeLong+ 。*/RingMinBufferOld=RingMinBuffer 。 if(Music_Sound_Long1i=0> DiplayClock(DisplayArrDisplyMode>。i=0 。Sound_Long_Count=Music
21、_Sound _Long1i 。 /*/Period=Music_Sound_Tone1i。TL1=(65536-Period>&0xff 。TH1=(65536-Period>>>8 。DiplayClock(Disp layArrDisplyMode> 。i+ 。if(RingFlag=1>TR1=1。TR0=1。while(Sound_Long_Count!=0> DiplayClock(DisplayArrDisplyMode>。ModeButten(> 。DownButten(>。UpButten(> 。Dip
22、layClock(DisplayArrDisplyMode>if(RingFlag=0>Sound_Long_Count=0 。TR1=0。TR0=0。RingMinBufferOld=0xff 。break 。case 2:i=0 。DisplyMode=0 。while(DisplayArr01=RingMinBuffer>/*/* 是否响闹铃 2 程序 */if(DisplayArr01!=RingMinBuffer>RingMinBuffer=DisplayArr01RingTimeLong+ 。*/RingMinBufferOld=RingMinBuffer
23、。 if(Music_Sound_Long2i=0> DiplayClock(DisplayArrDisplyMode>i=0g2i 。Sound_Long_Count=Music_Sound_LonPeriod=Music_Sound_Tone2i 。TL1=(65536-Period>&0xff 。TH1=(65536-Period>>>8 。/ Display(> 。i+ 。if(RingFlag=2>TR1=1。TR0=1。while(Sound_Long_Count!=0>DiplayClock(DisplayArrDisplyMode>。ModeButten(> 。en(>。UpButtoDownButten(> 。DiplayClock(DisplayArrDis
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 部编版七年级下册第五单元 单元测试卷(含答案)
- 收藏酒回收合同范本
- 光缆质量合同范本
- 核酸期间订餐合同范本
- 购牛协议合同范本
- 会务协议合同范本
- 西瓜卖货合同范本
- 民间借贷公司合同范本
- 订婚用品租借合同范本
- 委托翻译排版合同范本
- CJ/T 327-2010球墨铸铁复合树脂检查井盖
- 产品售后服务方案模板
- 防雷防静电培训考试试题及答案
- 混凝土索赔协议书
- 社保返还协议书
- 2025年湖南省国际工程咨询集团有限公司招聘笔试参考题库附带答案详解
- 变电站施工考试试题及答案
- 2025年农机修理工岗位职业技能资格考试练习题库(附答案)
- 中小学违规办学行为治理典型案例与规范要求
- 《实验室用电安全》课件
- 足少阴肾经试题及答案
评论
0/150
提交评论