We use an actual clock circuit to illustrate the software programming method of the timer. The clock is our most common timing tool that displays hours, minutes, and seconds. It is a typical application representative.
The minimum unit of the clock is seconds, but if the microcontroller timer is used for timing, if a 6.0MHz crystal oscillator is used, even if it works in working mode 1, the maximum timing time can only reach 131ms, so we can take each timing time as 125ms, so that the timer overflows 8 times (125ms╳8=1000ms) to get the minimum unit of seconds. It is easy to achieve 8 counts using software methods.
We use timer 1, working in working mode 1, and the timer performs 125ms timing. The interrupt method is used to accumulate the number of overflow times. When the overflow times are reached 8 times, 1 second of timing is obtained.
The time accumulation of a clock requires multiple bases to realize the carry of minutes and hours. The carry of seconds, minutes and hours is in decimal, while the carry of seconds to minutes and minutes to hours is in sexagesimal. There is a twelve-hour system or a twenty-four-hour system every day, which are in duodecimal and twentieth-century respectively. From seconds to minutes and from minutes to hours can be realized through software accumulation and numerical comparison methods.
In the internal RAM of the single-chip microcomputer, it is necessary to set up a display buffer. The displayed hour, minute, and second values are taken out from the display buffer. Four units are set up in the RAM as display buffers, namely 7AH, 7BH, and 7CH. In order to facilitate the description of the circuit and principle, we do not display the second value here. We realize the carry of the second by flashing the minute value. In this way, we have a total of four LEDs to display the hour and minute values respectively. At the same time, the clock needs to be calibrated. In the program, it is also necessary to set up a display code table. The value to be displayed is sent to the LED through the table lookup instruction to send the real code value for display. We use the two I/O ports PP3.4 and P3.5 of the single-chip microcomputer AT89C2051 to connect micro switches to realize the correction of hours and minutes. Each time the hour or minute value is pressed, 1 is added. The value is accumulated by pressing continuously to realize the calibration of the clock.
We also set a buzzer in the circuit for simple time reporting. For example, we can set a wake-up time of 7:30 in the morning and another wake-up time of 1:30 in the afternoon. Each time it rings for 1 minute, 1 second, and stops for 2 seconds, instead of continuous ringing. We use the 12-hour system in this program. For this reason, we need to set the corresponding flags in the program to facilitate the recognition of the main program. There are also several related flags in the timing program, which are mainly used to control the direction of the program flow. We have made detailed comments in the program, so I will not repeat them here.
For the hardware circuit, we still use the low-cost AT89C2051 microcontroller as the microprocessor unit. This chip is compatible with the C51 instruction system. Programs written on C51 can be easily transplanted to this chip without any modification. We use P0 port as the field bit drive output of the LED. The "carry" of the second uses the fractional value flashing prompt, which is on for 0.5 seconds and off for 0.5 seconds. P3.1-P3.3 are used for bit drive, and the dynamic scanning method is used for display. The display time of each LED can be between 10-25ms. The scanning frequency cannot be too high, otherwise the display time of each LED is too short and the brightness is too low, which is not easy to watch. It is better to make the naked eye not feel the LED flickering. For the sake of intuitiveness, our drive output does not use integrated circuits, but uses discrete components-transistors, but the working principle is the same.
This circuit structure determines that the LED uses a common anode digital tube, which can be LQ5101BS ordinary light-emitting diodes, and the driving transistors can use the easily available 2SA1015 and 2SC1815 models. Of course, low-power transistors such as S9012, S9013, S9014, 2N5401, 2N5555 can also be used. There are no special requirements for other devices. For the convenience of experiments, the single-chip microcomputer AT89C2051 can use a DIP20P socket. After the program is compiled and debugged without error, it can be burned into the AT89C2051. It is worth mentioning that AT89C2051 is a Flash program memory, and the program can be repeatedly erased and written, which is very convenient for experiments.
Previous article:Design of wireless transceiver system based on nRF905 module and C8051F microcontroller
Next article:Design of home appliance control system based on AT89S52 single chip microcomputer
Recommended ReadingLatest update time:2024-11-16 20:38
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
- Basic Theory of System Timing
- Mitsubishi Servo Drive MR-J2S-20B Disassembly
- Image processing filtering algorithm
- Application of RFID and other Internet of Things technologies in smart ranches
- EEWORLD University Hall ---- Engineering Test Technology Foundation Huazhong University of Science and Technology
- Looking for national standards? Here is the national standards website, which will definitely be useful to you!
- How to achieve automated testing of LCR?
- Which company can make PCB boards with a width of about 2MM?
- How to speed up the program running speed of Huada HC32F460 HC32F4A0?
- Namisoft's design report on labview spectrum analyzer