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.
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
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- Why do different simulation results appear when the parameters of this simulation routine are set the same?
- Keil strange compilation problem
- EEWORLD University Hall----Live Replay: TI's Latest Application of Millimeter-Wave Radar in the Automotive Field
- Design of temperature measurement system based on msp430 single chip microcomputer
- Single power supply single op amp second order filter plus DC bias (cannot be isolated)
- Book now to get a gift: 2019 Keysight Electronic Measurement Basics Online Lecture Series
- Thank you + my parents
- Useful Information | A technical expert shares 15 tips on power MOSFET [Collect it]
- New Industry, New Smart Manufacturing——STMicroelectronics Industrial Tour 2019 Chengdu invites you to participate!
- Apply for a trial of a new Tektronix oscilloscope and win a custom T-shirt!