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
Previous article:Several key points of low power consumption control and design
Next article:High-speed AVR realizes vibration/temperature signal acquisition and storage
- High signal-to-noise ratio MEMS microphone drives artificial intelligence interaction
- Advantages of using a differential-to-single-ended RF amplifier in a transmit signal chain design
- ON Semiconductor CEO Appears at Munich Electronica Show and Launches Treo Platform
- ON Semiconductor Launches Industry-Leading Analog and Mixed-Signal Platform
- Analog Devices ADAQ7767-1 μModule DAQ Solution for Rapid Development of Precision Data Acquisition Systems Now Available at Mouser
- Domestic high-precision, high-speed ADC chips are on the rise
- Microcontrollers that combine Hi-Fi, intelligence and USB multi-channel features – ushering in a new era of digital audio
- Using capacitive PGA, Naxin Micro launches high-precision multi-channel 24/16-bit Δ-Σ ADC
- Fully Differential Amplifier Provides High Voltage, Low Noise Signals for Precision Data Acquisition Signal Chain
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University Hall----Application of TI? Interface Chips in Automotive Products
- EEWORLD University ---- IoT Moment: Protocol Standards Driving the Development of IoT
- A simple pull-up and pull-down circuit causes the control chip to heat up!
- I would like some advice on how to import .brd files into DXP
- [RT-Thread reading notes] Part 2: Implementing multithreading
- VGA Display Circle - Simple Design and Application FPGA
- [NXP Rapid IoT Review] Rapid IoT Studio Simple Programming Step 2 Counter plus Bluetooth
- What does this PCB package marking mean?
- Problems found during PCB rule checking
- Study and use of DSP6678 chip