基于51单片机的多功能电子钟设计
基于51单片机的多功能电子钟设计
【摘要】数字电子时钟是人们日常生活中不可或缺的必需品。本文以STC89C52为核心控制芯片,DS12887为时钟芯片,DS18B20为温度传感器,通过液晶显示器LCD1602实时显示时间及温度,通过按键设置年月日和星期以及定时闹钟,定时闹钟时间到自动发出警报。本设计的+5V电源采用LM1117电压转换元件,将电源适配器转换得到的12V电压直接变成5V电压供系统使用。程序的下载则是通过普中科技公司自制的PZ-ISP软件完成。经过测试,系统可以正常完成预定的功能。
【关键词】电子时钟;单片机;DS12887;DS18B20;
基于51单片机的多功能电子钟设计
Design of Multi-function Clock Based on 51 MCU
【Abstract】Digital electronic clock is an integral, necessary part of daily life.In this paper, STC89C52 chip is used as the core control chip, DS12887chip is used as the clock chip, DS18B20 chip is used as the temperature sensor and LCD1602 was used to diaplay time and temperature。 You can set year, month and time alarm clock through the four buttons.When the real time reach to the time clock,the system will warn automatically. The +5V power of the system is supplied by LM1117 voltage conversion device. The 12V voltage get from power adapter was transformed directly into 5V voltage for the system. The download of the process is accomplished through the PZ-ISP software made by Puzhong technology company. After testing, the system can complete the scheduled function normally.
【key words】electronic clock;MCU;DS12887;DS18B20
基于51单片机的多功能电子钟设计
目 录
第一章 绪论 --------------------------------------------------------------------------------------------------- 1
1.1电子时钟的研究背景 ------------------------------------------------------------------------------ 1 1.2电子时钟的国内外研究现状 --------------------------------------------------------------------- 1 第二章 总体方案 --------------------------------------------------------------------------------------------- 4
2.1 系统的设计思路 ----------------------------------------------------------------------------------- 4 2.2 系统硬件描述 -------------------------------------------------------------------------------------- 4 2.3 系统软件描述 -------------------------------------------------------------------------------------- 4 2.4 设计流程和预期成果 ----------------------------------------------------------------------------- 5 第三章 硬件设计 --------------------------------------------------------------------------------------------- 6
3.1 硬件芯片介绍 -------------------------------------------------------------------------------------- 6
3.1.1 单片机STC89C52 ------------------------------------------------------------------------ 6 3.1.2 实时时钟芯片DS12887---------------------------------------------------------------- 10 3.1.3 温度传感器DS18B20 ------------------------------------------------------------------ 14 3.1.4 液晶显示屏LCD1602 ------------------------------------------------------------------ 18 3.2 系统硬件架构 ------------------------------------------------------------------------------------ 20
3.2.1 单片机最小系统 ------------------------------------------------------------------------- 21 3.2.2 时钟模块 ---------------------------------------------------------------------------------- 23 3.2.3 温度传感器模块 ------------------------------------------------------------------------- 24 3.2.4 液晶显示模块 ---------------------------------------------------------------------------- 25 3.2.5 按键模块 ---------------------------------------------------------------------------------- 26 3.2.6 蜂鸣器报警模块 ------------------------------------------------------------------------- 27
第四章 软件设计 ------------------------------------------------------------------------------------------- 29
4.1 软件设计总体说明 ------------------------------------------------------------------------------ 29 4.2 主程序软件实现 --------------------------------------------------------------------------------- 29
4.2.1主程序流程图 --------------------------------------------------------------------------- 29 4.2.2主程序代码 ------------------------------------------------------------------------------ 30 4.3 DS18B20模块软件实现 ------------------------------------------------------------------------ 32
4.3.1 DS18B20模块子程序流程图 --------------------------------------------------------- 32 4.3.2 DS18B20模块子程序代码 ------------------------------------------------------------ 32 4.4 LCD1602模块软件实现 ------------------------------------------------------------------------ 35
4.4.1 LCD1602液晶显示模块子程序流程图 --------------------------------------------- 35 4.4.2 LCD1602液晶显示模块子程序代码 ------------------------------------------------ 36 4.5 DS12887模块软件实现 ------------------------------------------------------------------------- 39
4.5.1 DS12887模块子程序流程图 ---------------------------------------------------------- 39 4.5.2 DS12887模块子程序代码 ------------------------------------------------------------- 40 4.6 报警模块软件实现 ------------------------------------------------------------------------------ 51
4.6.1 报警模块子程序流程图 ---------------------------------------------------------------- 51
基于51单片机的多功能电子钟设计
4.6.2 报警模块子程序代码 ------------------------------------------------------------------- 52
第五章 系统调试 ------------------------------------------------------------------------------------------- 56
5.1 最小系统的调试 --------------------------------------------------------------------------------- 56 5.2 液晶显示模块和蜂鸣器报警模块的调试 --------------------------------------------------- 56 5.3 整体调试 ------------------------------------------------------------------------------------------ 56 5.4 实物图 --------------------------------------------------------------------------------------------- 56 第六章 总结 ------------------------------------------------------------------------------------------------- 58 致 谢--------------------------------------------------------------------------------------------------------- 59 参考文献 ----------------------------------------------------------------------------------------------------- 60 附录A 电路原理图 ---------------------------------------------------------------------------------------- 61 附录B 程序头文件 ---------------------------------------------------------------------------------------- 62