Design of a multifunctional electronic perpetual calendar based on single chip microcomputer (Part 1)

Publisher:心境恬淡Latest update time:2012-11-15 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

As the pace of life accelerates, people's concept of time becomes more and more important, and the demand for electronic clocks and calendars increases. Therefore, the study of practical electronic clocks and their extended applications has a very practical significance and great practical value.

This system program consists of a main program, an interrupt service function, and multiple sub-functions. The main function is mainly used to initialize each sub-function and interrupt function. The timing interrupt function is mainly used to complete the timing scan of the clock chip and the keyboard scan. The read and write functions of the clock chip are mainly used to read the time and calendar information, and write the specific values ​​to be modified into the clock chip.

System hardware design and circuit principle

Circuit design block diagram

System Hardware Overview

This circuit is controlled by AT89S52 single-chip microcomputer, with online programming function, low power consumption, and can work at ultra-low voltage of 3V. The clock circuit is provided by DS1302, which is a high-performance, low-power, real-time clock circuit with RAM. It can count the year, month, day, weekday, hour, minute, and second, and the working voltage is 2.5V~5.5V. It uses a three-wire interface to communicate synchronously with the CPU, and can use burst mode to transmit multiple bytes of clock signals or RAM data at a time. There is a 31×8 RAM register inside DS1302 for temporary storage of data. It can generate year, month, day, weekday, hour, minute, and second, and has the characteristics of long service life, high precision and low power consumption, and also has the function of automatic saving when power is off.

Main control module

Design of the main control module of the single chip microcomputer

The AT89S52 microcontroller is a 40-pin dual in-line chip with four I/O ports P0, P1, P2, and P3. The MCS-51 microcontroller has a total of four 8-bit I/O ports (P0, P1, P2, and P3). Each I/O line can be used independently for output or input.

Clock circuit module

Design of clock circuit module

The pin arrangement of DS1302 is shown in Figure 3, where Vcc1 is the backup power supply and Vcc2 is the main power supply. Even when the main power supply is turned off, the clock can still run continuously. DS1302 is powered by the larger of Vcc1 or Vcc2. When Vcc2 is greater than Vcc1+0.2V, Vcc2 powers DS1302; when Vcc2 is less than Vcc1, DS1302 is powered by Vcc1. X1 and X2 are oscillation sources, connected to an external 32.768KHz crystal. RST is the reset/chip select line, which starts all data transfers by driving the RST input high. The RST input has two functions: first, RST turns on the control logic, allowing the address/command sequence to be sent to the shift register; second, RST provides a means to terminate the transmission of single-byte or multi-byte data.

Figure 1 Overall circuit diagram

Figure 2 Main control system

Figure 3 Clock control system

Working principle of clock circuit module

DS1302 must be initialized before each read or write program. First, set the SCLK terminal to "0", then set the RST terminal to "1", and finally give the SCLK pulse; the read/write timing is shown in Figure 4. Table 1 is the control word of DS1302. Bit 7 of this control word must be set to 1. If it is 0, data cannot be read or written to DS1302. For bit 6, if RAM=1 when reading/writing the program, CK=0 when reading/writing the time. Bits 1 to 5 refer to the address of the operation unit. Bit 0 is the read/write operation bit. When performing a read operation, this bit is 1; when this bit is 0, it means that a write operation is being performed. The control byte is always input/output from the lowest bit. Table 2 shows the contents of the calendar and time registers of DS1302: "CH" is the clock pause flag bit. When this bit is 1, the clock oscillator stops and DS1302 is in a low power state; when this bit is 0, the clock starts running. "WP" is the write protection bit. Before any write operation to the clock and RAM, WP must be 0. When "WP" is 1, the write protection bit prevents write operations to any register.

DS1302 control byte

The control word of DS1302 is shown in Table 1. The high-significant bit (bit 7) of the control byte must be logic 1. If it is 0, data cannot be written into DS1302. If bit 6 is 0, it means accessing calendar clock data, and 1 means accessing RAM data; bits 5 to 1 indicate the address of the operation unit; the least significant bit (bit 0) indicates a write operation if it is 0, and a read operation if it is 1. The control byte is always output from the lowest bit.

Data input and output (I/O)

At the rising edge of the next SCLK clock after the control instruction word is input, data is written into DS1302, and data input starts from the low bit, i.e., bit 0. Similarly, at the falling edge of the next SCLK pulse following the 8-bit control instruction word, data from DS1302 is read out, and data is read out from the low bit 0 to the high bit 7, as shown in Figure 4.

Table 1 DS1302 control word format

Figure 4 DS1302 read/write timing diagram

DS1302 Registers

DS1302 has 12 registers, 7 of which are related to the calendar and clock. The data bits stored are in BCD code format. The calendar, time registers and their control words are shown in Table 2.

In addition, DS1302 also has year register, control register, charging register, clock burst register and RAM-related registers. The clock burst register can read and write all register contents except the charging register in sequence at one time. DS1302 RAM-related registers are divided into two categories: one is a single RAM unit, a total of 31, each unit is configured as an 8-bit byte, and its command control word is C0H~FDH, where odd numbers are read operations and even numbers are write operations; the other is the RAM register in burst mode, in which all 31 bytes of RAM can be read and written at one time, and the command control word is FEH (write) and FFH (read).

Clock module implementation function

This module provides the system with accurate real-time time information such as seconds, minutes, hours, days, months, and years, while the day of the week is calculated by programming.

Temperature acquisition module

Temperature acquisition module design

As shown in Figure 5. The digital temperature sensor DS18B20 is used, which has the characteristics of high measurement accuracy and simple circuit connection. This type of sensor only needs one data line for data transmission. Use P1.7 to connect to the I/O port of DS18B20 and add a pull-up resistor, Vcc1 to the power supply, and Vcc2 to the ground.

Temperature measurement principle of DS18B20

The oscillation frequency of the low temperature coefficient crystal oscillator is little affected by temperature. It is used to generate a fixed frequency pulse signal to the subtraction counter 1. The oscillation frequency of the high temperature coefficient crystal oscillator changes significantly with temperature. The generated signal is used as the pulse input of the subtraction counter 2. When the counting gate is opened, the DS18B20 counts the clock pulses generated by the low temperature coefficient oscillator, and then completes the temperature measurement. The opening time of the counting gate is determined by the high temperature coefficient oscillator. Before each measurement, the base number corresponding to -55℃ is first placed in the subtraction counter 1 and the temperature register respectively. The subtraction counter 1 and the temperature register are preset to a base value corresponding to -55℃. The subtraction counter 1 subtracts the pulse signal generated by the low temperature coefficient crystal oscillator. When the preset value of the subtraction counter 1 is reduced to 0, the value of the temperature register will be increased by 1, and the preset of the subtraction counter 1 will be reloaded. The subtraction counter 1 starts to count the pulse signal generated by the low temperature coefficient crystal oscillator again. This cycle continues until the subtraction counter 2 counts to 0, and the accumulation of the temperature register value is stopped. At this time, the value in the temperature register is the measured temperature. The slope accumulator is used to compensate and correct the nonlinearity in the temperature measurement process, and its output is used to correct the preset value of the subtraction counter. As long as the counting gate is not closed, the above process is repeated until the temperature register value reaches the measured temperature value.

Table 2 DS1302 calendar and time registers

Figure 5 DS18B20 temperature acquisition

Display module design

This design uses LED dynamic display. Since there is no LED in PROTEUS, LCD is used instead of LED for simulation and connected to the main control chip AT89C52, as shown in Figure 6.

System software design

Figure 6 LED dynamic scanning display

Figure 7 Main program flow chart

Reference address:Design of a multifunctional electronic perpetual calendar based on single chip microcomputer (Part 1)

Previous article:Several key points of low power consumption control and design
Next article:High-speed AVR realizes vibration/temperature signal acquisition and storage

Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号