目录1绪论·····························································································12总体设计方案················································································22.1设计思路··················································································22.2设计方案··················································································22.3方案比较论证···········································································22.4总体设计方框图········································································33设计原理与分析·············································································43.1硬件电路主要芯片的功能介绍······················································43.1.1单片机主控制器·························································································43.1.2温度传感器芯片························································································53.1.3时钟芯片DS1302·······················································································93.1.416*2LCD液晶显示1602··········································································124硬件电路······················································································154.1单片机主控制模块的设计···························································154.2时钟电路模块的设计·································································154.3温度采集模块设计····································································164.4功能按钮设计··········································································164.516*2LCD1602液晶显示电路设计·················································174.6总体电路图··············································································175系统软件设计···············································································185.1系统模块的功能分划分······························································185.2总体程序流程框图····································································185.3时钟调整时间的流程图······························································205.4修改键“UP”的功能流程图························································215.5温度转换流程图·······································································226系统仿真测试···············································································236.1KEIL的使用············································································236.2PROTUES软件仿真·······································································28致谢····························································································31参考文献·························································································32附录一总体电路的PCB板图·····························································33附录二设计电路的仿真电路图··························································34附录二万年历源程序······················································································3511绪论随着电子技术的迅速发展,特别是随大规模集成电路出现,给人类生活带来了根本性的改变。由其是单片机技术的应用产品已经走进了千家万户。其中电子万年历就是一个典型的例子。而且在万年历的基础上还可以扩展其它的实用功能,比如温度计。万年历是采用数字电路实现对.时,分,秒.数字显示的计时装置,广泛用于个人家庭,车站,码头办公室等公共场所,成为人们日常生活中不可少的必需品,由于数字集成电路的发展和石英晶体振荡器的广泛应用,使得数字钟的精度,远远超过老式钟表,钟表的数字化给人们生产生活带来了极大的方便,而且大大地扩展了钟表原先的报时功能。诸如定时自动报警、按时自动打铃、时间程序自动控制、定时广播、自动起闭路灯、定时开关烘箱、通断动力设备、甚至各种定时电气的自动启用等,但是所有这些,都是以钟表数字化为基础的。因此,研究万年历及扩大其应用,有着非常现实的意义。市场上有许多电子钟的专用芯片如:LM8363、LM8365等,但它们功能单一,电路连接复杂,不便于调试制作。但是考虑到用单片机配合时钟芯片,可制成功能任意的电子钟,而且可以做到硬件简单、成本低廉。所以本系统采用了以广泛使用的单片机AT89S52技术为核心,配合时钟芯片DS1302。软硬件结合,使硬件部分大为简化,提高了系统稳定性,并采用LCD显示电路、键盘电路,使人机交互简便易行,此外结合音乐闹铃电路、看门狗和供电电路。本方案设计出的数字钟可以显示时间、设置闹铃功能之外。本文首先描述系统硬件工作原理,并附以系统结构框图加以说明,着重介绍了本系统所应用的各硬件接口技术和各个接口模块的功能及工作过程,其次,详细阐述了程序的各个模块和实现过程。本设计以数字集成电路技术为基础,单片机技术为核心。本文编写的主导思想是软硬件相结合,以硬件为基础,来进行各功能模块的编写。本设计中我重点研究实现了单片机+时钟芯片这种模式的万年历,从原理上对单片机和时钟芯片有了深一步的认识,这些基本功能完成后,在软件基础上实现时间显示。22总体设计方案2.1设计思路用AT89S52处理产生内部时钟数据或者读取外部时钟数据和采集外部传感器的信息进行处理,并暂时寄存在其内部的储存器中,再通过单片机调用内部RAM的数据并送到LCD或者LED数码管上显示出来。2.2设计方案方案1:单片机一般的工作频率在12MHz左右,而且内部还有定时、计数器,可以产生精确的1S定时,由次可以用定时中断的方式产生精确的1S时间,秒位不断的加1,再设计分、时、星期、日、月、年之间的进制,使产生进位。本方案只需要单片机最小系统加上显示电路,再设计简单的程序算法就可以实现。对于测温电路,可以使用热敏电阻之类的器件利用其感温效应,在将随被测温度变化的电压或电流采集过来,进行A/D转换后,就可以用单片机进行数据的处理。在显示电路上,采用数码管就可以将年月日星期时分秒和室内温度显示出来方案2:万年历时钟采用单片机控制DS1302实时时钟芯片,能达到走时准确且掉电不丢失数据的。DS1302与单片机之间能简单地采用同步串行的方式进行通信仅需用到三个口线1RES(复位)2I/O(数据线)3SCLK(串行时钟)。温度计要灵敏反映室温的变化这样可采用单片机与数字式温度传感器DS18B20通讯,采集温度数字信号进行处理。DS18B20通过一个单线接口发送或接受信息,因此在单片机与DS18B20之间仅需一条连接(加上地线)。在显示电路上,采用16*2的LCD显示。2.3方案比较论证对于方案1,单片机虽然可以产生精确的秒信号,但是单片机在处理闰年上会比较麻烦,加之一旦单片机断电后,所有的时间都要重新调整。对于测温电路,采用热敏电阻的输出电压-温度特性,要加上A/D转换,温度传感信息才能被单片机所接受,这种设计需要用到A/D转换电路,感温电路比较麻烦。在显示电路上,采用LED数码的话要用到单片机的许多I/O口,甚至I/O不够用,还需要接上其它芯片大量扩展I/O口,这是一个弊处。对于方案2:单片机不用去产生时钟的数据,时钟的数据由DS1302独立产生,并寄存在其内部的寄存器上,单片机可以通过三总线与它通讯,不仅可以对它进行读取实时时钟数据,还可以对它进行编程,设置它的工作模式。单片机只是处理从DS1302读出来的数据并送显示,大大减少了单片机的负担。而且DS13023可以通过后备电池继续工作,内部的时钟还在走,下次启动后不用去调整时钟,方便使用。基于同样的原理,DS18B20也是一个独立的传感器,只要单片机配置它的工作状态后它就可以独立工作,内部已经把模拟信号转换成数字信号,并把数字信号储存在其内部的寄存中。同样,单片机通过单总线与它通讯,可以处理9~12位的温度数字数据。在显示电路上,采用16*2LCD液晶显示器,能容纳年月日星期时分秒温度等信息的显示。LCD显示器只需占用11个I/O口就可以工作了,不用其它扩展芯片,总体上使电路简单化。2.4总体设计方框图总体的方框图如图2.1所示,控制器采用单片机AT89S52,温度传感器采用DS18B20,用16*2的LCD液晶显示屏实现年、月、日、星期、时、分、秒、温度的显示。图2.1总体设计方框图AT89S52主控制器DS130