Design of Multifunctional Electronic Perpetual Calendar Based on Single Chip Microcomputer

Publisher:创新驿站Latest update time:2012-11-07 Source: 21IC Keywords:MCU 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, externally connected to a 32.768KHz crystal oscillator. 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; if 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. P1.7 is connected to the I/O port of DS18B20 with a pull-up resistor, Vcc1 is connected to the power supply, and Vcc2 is connected 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.

[page]

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

Main program flow chart

Keil C and Proteus joint debugging and test results

Proteus7.6 is currently the best tool for simulating microcontroller peripheral devices. It can simulate commonly used MCUs such as 51 series, AVR, PIC and their peripheral circuits (such as LCD, RAM, ROM, keyboard, motor, LED, AD/DA, some SPI devices, some IIC devices, etc.). Using Proteus7.6 and Keil C, you can debug the program like using an emulator.

Working process of Proteus

After running the ISIS program of Proteus, enter the main interface of the simulation software as shown in Figure 8. Before working, set the snap alignment under the view menu and the color, graphic interface size and other items under the system. Use the p (select component from library command) command in the toolbar to select the components required for the circuit in the pick devices window, place the components and adjust their relative positions, component parameter settings, connections between components, and write programs; under the Define code generation tools menu command of the source menu, select the tools, paths, extensions and other items for program compilation; under the Add/remove source files command of the source menu, add the corresponding program of the microcontroller hardware circuit; and use the corresponding commands of the debug menu to simulate the operation of the program and circuit.

Figure 8 Proteus startup interface

Debugging methods provided by Proteus software

Proteus provides a rich set of test signals for circuit testing. These test signals include analog signals and digital signals. For debugging of microcontroller hardware circuits and software, Proteus provides two methods: one is the overall execution effect of the system, and the other is the step-by-step debugging of the software to see the specific execution status.

Application system combining software and hardware

The combination of software and hardware is a single-chip microcomputer application system. At this stage, the design of the hardware circuit is no longer the most critical, and the design, debugging and operation of the software system are the main contents of the experiment. Therefore, specific hardware circuits can be given with suggestive opinions, and the specific work that the circuit needs to complete can be proposed to design and debug the software.

Introduction of Keil C

Keil C running interface

The running interface after running Keil C is shown in Figure 9.

Figure 9 Keil C running interface

Keil C and proteus joint debugging test

1. Install keil and proteus7.6;

2. Open proteus and draw the corresponding circuit. Select use remote debug monitor in the tools menu of proteus;

3. Write the MCU program in Keil;

4. Enter the project menu of Keil and select option for target \'project name\'. In the DEBUG option, select Proteus VSM Monitor-51 Driver from the drop-down menu on the upper right column;

5. Debug in Keil and view the intuitive results in Proteus and LCD display;

6. Compile the file in Keil and output a hex file. In Proteus, replace the MCU loader file with the hex file in Keil and then run it. [page]

Operation Results

Results

From the overall circuit block diagram of FIG1 , it can be seen that the LED display result is as shown in FIG10 .

Figure 10 Results display

Adjust the display

The modification of date and time consists of 4 buttons. Key P0 is adjustment; P2^0, mode switch key (move left) move left; key P2^1, addition button; key P2^2, subtraction button; key P2^3, immediately jump out of the adjustment mode button.

When you press PO, the seconds will flash and you will enter the adjustment system, as shown in Figure 11.

Press P2^0 to move left to adjust the minutes, as shown in Figure 12.

Press P2^1 to move left to adjust the time, as shown in Figure 13.

Figure 11 Second adjustment

Figure 12: Adjustment

Figure 13 Time adjustment

Figure 14 shows the display before adjustment. Press P2^2 to move left to adjust the year downward, as shown in Figure 15.

Press P2^3 to move left to exit adjustment and restore as shown in Figure 16.

Figure 14 Display before adjustment

Figure 15 Annual reduction adjustment

Figure 16 Exit adjustment system

Summarize

This paper designs a multifunctional electronic perpetual calendar. The circuit is controlled by AT89S52 single-chip microcomputer, and the hardware system is composed of clock chip DS1302, temperature chip DS18B20, buttons, LED display and other modules. There are 3 independent buttons in the hardware system, which can calibrate the time, select time, display temperature, etc. at any time according to the needs of the user. In summary, this perpetual calendar has many advantages such as easy reading, intuitive display, diverse functions, simple circuit, low cost, etc. It conforms to the development trend of electronic instruments and has broad market prospects.

In the whole design process, I gave full play to my subjective initiative, studied independently, learned a lot of knowledge that I had not learned before, increased the test of my hands-on ability, and achieved the expected goal. In short, this design has improved my ability in all aspects.

Keywords:MCU Reference address:Design of Multifunctional Electronic Perpetual Calendar Based on Single Chip Microcomputer

Previous article:FPGA Configuration Based on Single Chip Microcomputer P89C61X2
Next article:Design of Arbitrary Waveform Generator Based on CPLD and Single Chip Microcomputer

Recommended ReadingLatest update time:2024-11-16 14:44

Next Generation Automotive Microcontrollers
STMicroelectronics is committed to helping the automotive industry meet the challenges of electrification and digitalization. It not only provides the solutions needed at this stage, but also provides a more powerful unified MCU platform development strategy in the future, supporting the development of next-generati
[Automotive Electronics]
Design of Internet Broadcasting Based on ARM 926EJ-S Microcontroller
This paper proposes a network broadcast design scheme for embedded systems based on ARM and PoE. The scheme uses the ARM926EJ-S processor and its peripheral modules as the hardware platform and embedded Linux as the operating system to form the entire system. The system uses Ethernet power supply to realize the functio
[Analog Electronics]
Design of Internet Broadcasting Based on ARM 926EJ-S Microcontroller
51 MCU i2c memory 24c02 driver
This is the circuit diagram , this is the file taken from this project which contains the circuit diagram and simulation file: http://www.51hei.com/bbs/dpj-22586-1.html Below is the i2c.c file: #include reg52.h #include "i2c.h" #include "delay_ms.h" void delay()  {  ;; } void i2cinit()// bus initializat
[Microcontroller]
51 MCU i2c memory 24c02 driver
A solution for joint simulation of hardware and software based on single chip microcomputer
  Abbreviations:   BFM: Bus Function Module. In HDL hardware language simulation, BFM completes the conversion between abstract description data and specific timing signals.   PLI: Verilog Programming Language Interface, which is the interface definition for exchanging data between C language modules and Verilog l
[Microcontroller]
A solution for joint simulation of hardware and software based on single chip microcomputer
52 MCU timer/counter programming summary
/*----------------------------------------------------------------------                             TMOD (89H)                     T1 T0       GATE C/T` M1 M0 GATE C/T` M1 M0 ------------------------------------------------------------------------ When GATE=0, TR0=1, T0 starts timing/counting When GATE=1, TR0=1, INT0
[Microcontroller]
51 MCU resources - EEPROM (IIC bus)
Composition and working principle of I2C serial bus The use of serial bus technology can greatly simplify the hardware design of the system, reduce the size of the system, and improve reliability. At the same time, the system can be easily modified and expanded. I2C Serial Bus Overview The I2C bus is a serial bus in
[Microcontroller]
51 MCU resources - EEPROM (IIC bus)
51 MCU Series - How to use timers T0 and T1
Example 1: Square Wave Generator The source code is as follows: main.c #include reg52.h sbit Square=P1^5; //Set square wave output pin P1^5 void main(void){  TMOD=0x02; //Configure TMOD: timer, working mode 2 (automatically reload initial value)  TH0=0x06; //Mode 2, pre-installed value  TL0=0x06; //Mode 2, counte
[Microcontroller]
51 MCU Series - How to use timers T0 and T1
Universal password lock controlled by 51 single chip microcomputer
Initial password: 12345678 This program is implemented by using 51 single chip microcomputer to control 74LS164 latch The MCU and the memory use IIC communication to establish the cryptographic system communication. Simulation starts and password is set Universal password lock reference program source code: #inc
[Microcontroller]
Universal password lock controlled by 51 single chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号