Technology Sharing

【TB Works】51 MCU Proteus simulation based on MCU LCD12864 perpetual calendar and temperature monitoring system design

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

insert image description here

Experimental report: Design of LCD12864 perpetual calendar and temperature monitoring system based on single chip microcomputer

Background

This experiment aims to design and implement a perpetual calendar system based on LCD12864 display of STC89C52 microcontroller, and integrate temperature sensor to realize temperature monitoring function. The system has hourly time and alarm functions, and prompts through buzzer. This design can not only realize basic clock and temperature display, but also has certain alarm functions, which is suitable for scenes such as home or office.

Hardware Introduction

  1. STC89C52 MCU:As the core controller of the system, it is responsible for handling the implementation of various functions.
  2. LCD12864 display: Used to display information such as time, date and temperature.
  3. DS18B20 Temperature Sensor: Used to monitor ambient temperature in real time.
  4. buzzer: Used for hourly time reporting and alarm reminders.
  5. Button module: Used for users to set time and alarm function.
  6. Other electronic components: Such as resistors, capacitors, etc., used for circuit construction and stable operation.

Circuit Design

The circuit is mainly composed of a single-chip microcomputer, an LCD display, a temperature sensor and a buzzer. The LCD12864 display is connected to the single-chip microcomputer through a parallel interface, the DS18B20 temperature sensor is connected to the single-chip microcomputer through a single-line interface, and the buzzer is controlled by the I/O port of the single-chip microcomputer.

Main connection instructions

  1. LCD12864 display
    • Data ports D0-D7 are connected to the microcontroller P0 port.
    • The control signals RS, RW, and E are connected to P2.0, P2.1, and P2.2 of the microcontroller respectively.
  2. DS18B20 Temperature Sensor
    • The data port DQ is connected to the P3.7 port of the microcontroller.
  3. buzzer
    • Connect to the P2.0 port of the microcontroller.
  4. Button module
    • Each button is connected to the P1 port of the microcontroller for scanning and detecting the button status.

software design

system initialization

After the system is powered on, it is initialized first, including LCD display initialization, clock initialization, interrupt initialization, etc. The initialization code is as follows:

void main( void )
{
	uchar	clock_time[6]	= { 0X00, 0X59, 0X23, 0X09, 0X04, 0X11 };       /* 定义时间变量 秒  分 时 日 月 年 */
	uchar	alarm_time[2]	= { 10, 06 };                                   /* 闹钟设置  alarm_time[0]: 分钟  alarm_time[1] :小时 */
	uchar	temperature[2];                                                 /* 定义温度变量   temperature[0]  低8位   temperature[1]  高8位 */
	Lcd_Initial();                                                          /* LCD初始化 */
	Clock_Fresh( clock_time );                                              /* 刷新时间 */
	Clock_Initial( clock_time );                                            /* 时钟初始化 */

	/* 中断初始化 */
	EA	= 1;    /* 开总中断 */
	ET0	= 1;    /* Timer0 开中断 */
	ET2	= 1;    /* Timer2 开中断 */
	TMOD	= 0x01; /* Timer0 工作方式 1 */
	RCAP2H	= 0x3c;
	RCAP2L	= 0xb0; /* Timer2 延时 50 ms */
}

Time display and update

The system continuously refreshes the time in the main loop and displays it on the LCD. At the same time, the temperature value is read by the DS18B20 sensor and displayed on the LCD.

while ( 1 )
{
	Clock_Fresh( clock_time );      /* 时间刷新 */
	Lcd_Clock( clock_time );        /* 时间显示 */

	Sensor_Fresh( temperature );    /* 温度更新 */
	Lcd_Temperture( temperature );  /* 温度显示 */

	/* 整点报时 */
	if ( (*clock_time == 0x59)