《基于单片机的实时日历时钟显示系统》由会员分享,可在线阅读,更多相关《基于单片机的实时日历时钟显示系统(8页珍藏版)》请在金锄头文库上搜索。
1、XXXXXXX学 院 本 科 毕 业 设 计(论文)基于单片机的实时时钟显示系统设计学 院(系): 计算机科学与技术系 专 业: 通信工程 学 生 姓 名: 学 号: 指 导 教 师: 完 成 日 期: 摘 要20世纪末,电子技术获得了飞速的发展,在其推动下,现代电子产品几乎渗透了社会的各个领域,有力地推动了社会生产力的发展和社会信息化程度的提高,同时也使现代电子产品性能进一步提高,产品更新换代的节奏也越来越快。现代生活的人们越来越重视起了时间观念,可以说是时间和金钱划上了等号。对于那些对时间把握非常严格和准确的人或事来说,时间的不准确会带来非常大的麻烦,所以以数码管为显示器的时钟比指针式的时
2、钟表现出了很大的优势。数码管显示的时间简单明了而且读数快、时间准确显示到秒。而机械式的依赖于晶体震荡器,可能会导致误差。数字钟是采用数字电路实现对“时”、“分”、“秒”数字显示的计时装置。数字钟的精度、稳定度远远超过老式机械钟。在这次设计中,我们采用LED数码管显示时、分、秒,以24小时计时方式,根据数码管动态显示原理来进行显示,用12MHz的晶振产生振荡脉冲,定时器计数。在此次设计中,电路具有显示时间的其本功能,还可以实现对时间的调整。数字钟是其小巧,价格低廉,走时精度高,使用方便,功能多,便于集成化而受广大消费的喜爱,因此得到了广泛的使用。关键字:数字电子钟 单片机AbstractThe
3、late 20th century, electronic technology has been rapid development in its promotion,penetration of modern electronic products will almost Fields, a strong impetus to the development of social productive forces and social improvement in the level of information, while also further improve the perfor
4、mance of modern electronic products, replacement products have become increasingly fast pace. Growing emphasis on modern life from the time the concept of time and money can be said to draw the equal sign. For those who are very strict and accurate grasp of time and things, time will not exactly bri
5、ng a very big trouble, so as to control the display of digital clock than the clock pointer showed a big advantage. Digital display of time reading simple and fast, accurate display of time to seconds. The mechanical oscillator depends on the crystal may lead to errors. Digital Clock is a digital ci
6、rcuit implementation of the when, sub, seconds The figures show the timing device. Digital clock precision, stability, far more than the old mechanical clock. In this design, we use LED digital display hours, minutes, seconds, to 24-hour time mode, according to digital control theory to dynamic disp
7、lay to display, use the 12MHz crystal oscillation pulse, the timer count. In this design, the circuit has a display time of the this function, you can also realize the time adjustment. Digital clock is its compact, low cost, travel time and high precision, easy to use, features and more, easy integr
8、ation and loved by the general consumer, so widely used. Keywords: digital electronic clock SCM前 言本例的功能是在51单片机系统中设置,获取,记录实时的日历时钟信息并通过数码管显示,要求能够进行长时间的记录,并且存储的时间信息在掉电情况下至少保存10年以上。该系统包含5个模块:51单片机模块,日历时钟模块,数码管显示模块,串行通信模块,C51程序。本系统用到的电路及程序如下: 程序代码如下:#define_CALENDARCLK_H / 防止CalendarClk.h被重复引用#define_CAL
9、ENDARCLK_H#include #include #define uchar unsigned char#define unint unsigned int/* DS12C887 内部专用寄存器宏定义 */#define MIN XBYTE0x0102#define HOUR XBYTE0x0104#define DAYOFWEEK XBYTE0x0106#define DAYOFMONTH XBYTE0x0107#define MONTH XBYTE0x0108#define YEAR XBYTE0x0109#define REG_A XBYTE0x010a#define REG_B
10、XBYTE0x010b/* 由串口获得的日历时钟信息变量,用于对芯片时间的设置 */uchar year1,month1,dayofweek1,dayofmonth1,hour1,min1;/* 芯片DS12C887提供的日历时钟信息变量 */uchar year2,month2,dayofweek2,dayofmonth2,hour2,min2;/* 从串行口获取数据函数,数据包括:year1,month1,dayofweek1,dayofmonth1,hour1,min1。如果获取到正确数据则返回1,否则返回0 */uchar getdata()/ 略去/* 设置日历和时钟函数 */voi
11、d settime()REG_B = REG_B|0x80;/ SET=1,芯片DS12C887处于设置状态MIN = min1;HOUR = hour1;DAYOFWEEK = dayofweek1;DAYOFMONTH = dayofmonth1;MONTH = month1;YEAR = year1;REG_B = REG_B&0x7f; / SET=0,芯片DS12C887恢复正常数据更新状态/* 获取日历时钟信息函数 */void gettime()while (REG_A&0x80=0x00)/ 直到UIP=0时,才能读取日历时钟信息min2 = MIN ;hour2 = HOUR
12、;dayofweek2 = DAYOFWEEK;dayofmonth2 = DAYOFMONTH; month2 = MONTH;year2 = YEAR;/* 13位数码管显示年、月、日、星期、时、分 */void display()/ 略去/* 串口初始化函数 */void init_serial()TMOD = 0x20;/ 定时器T1使用工作方式2TH1 = 250;TL1 = 250;TR1 = 1;/ 开始计时PCON = 0x80;/ SMOD = 1SCON = 0x50;/ 工作方式1,波特率9600kbit/s,允许接收 void main(void)uchar setfl
13、ag;init_serial();/* 设置DV2、DV1、DV0为010,打开芯片DS12C877内部晶振 */REG_A = REG_A&0xaf;/ DV2=DV0=0REG_A = REG_A|0x20;/ DV1=0REG_B = REG_B&0x7b;/ SET=0,时间数据正常更新;DM=0,二进制数据模式REG_B = REG_B|0x02;/ 寄存器B的24/12位置1,24小时时间模式while (1)setflag = getdata();/ 通过查询方式获取串口数据/* 如果获取到正确数据,则设置时间 */if (setflag=0x01)settime();/* 调用获取日历时钟函数 */gettime();/* 13位数码管显示日历、星期和时间信息 */display();