Share this

A high-precision countdown system based on AT89C51 control

2026-04-06 05:57:41 · · #1

1 Introduction

The task of a countdown system is to count down to a set date and display the time from the current date to the set date on the screen, thereby increasing people's attention and sense of urgency. Development practice shows that a high-precision countdown system using the DS12C887 clock chip as the clock module and the AT89C51 microcontroller as the control module features high accuracy, the ability to operate continuously and stably for extended periods, and ease of use, thus well meeting practical needs. The system's hardware and software designs are as follows.

2. System Hardware Design

The system's control module is composed of an AT89C51 microcontroller, used to initialize the serial port controller and perform data reading and writing, as well as to identify, dump, and display various received data. The DS12C887 clock chip provides high-precision year, month, day, hour, minute, and second time, and is directly connected to the microcontroller after calibration. The countdown display module consists of LED digital tubes, a 74HC595 chip, and a 74LS245 chip.

The overall system block diagram is shown in Figure 1.

System overall structure diagram

Figure 1 System Overall Structure Diagram

2.1 Clock Module and its Connection with the Microcontroller

The clock module is used for timing hours, minutes, seconds, year, month, day, and day of the week. It is based on the DS12C887 clock/calendar chip manufactured by Dallas Semiconductor. This chip has high integration, providing year, month, day, hour, minute, and second information, and can be programmed to generate an interrupt at each moment. Its peripheral circuit design is simple, its performance is good, and its timing accuracy is high. The DS12C887 has 128 bytes of RAM, of which 11 bytes are used to store time information and 4 bytes are used to store control information (control registers). Users can access these registers at any time to control the DS12C887. 113 bytes of general-purpose RAM are also available for user use. Users can also program the DS12C887 to achieve various square wave outputs and control its three internal interrupts via software. The DS12C887 is a dual in-line package. Its connection to the microcontroller is as follows: AD0~AD7 bidirectional address/data multiplexed lines are connected to the microcontroller's P0 port for data exchange; the AS address strobe input pin is connected to the microcontroller's ALE pin for address latching and address data multiplexing; the CS chip select line is connected to the microcontroller's P2.6 pin for selecting the clock chip; the DS data strobe read input pin is connected to the microcontroller's read strobe pin for reading data from the chip; the R/W read/write input is connected to the microcontroller's write strobe pin for writing to the clock chip; MOT is directly grounded, using Intel timing; and the IRQ pin is connected to the microcontroller's INT1 pin to provide a time reference for time acquisition.

2.2 Design of the Display Module

The microcontroller processes the time information read from the DS12C887 and outputs a display signal to port P1. The displayed information includes countdown information (number of days until the set time) and the current day of the week, hour, minute, and second. The display circuit mainly consists of 9 LED digital tubes, 9 74HC595 chips, and 1 74LS245 chip.

The design employs a dynamic display method, where all segment select lines are connected in parallel and controlled by an 8-bit I/O port. The 74HC595 is a high-speed CMOS device with a silicon architecture, featuring an 8-bit shift register and a memory. It has tri-state output functionality; when the enable pin OE is low, it outputs the data from the memory register to the bus. Utilizing the output latch function of the 74HC595's parallel outputs, the display of the digital tube is controlled using a serial-in, parallel-out configuration. Specifically, the Q7 and SER pins of the chip are cascaded and connected to the microcontroller via three I/O ports. Pin 14 (SER) of the 74HC595 is the serial input; pin 12 (RCLR) is the shift clock, shifting data from pin 14 into the register on the rising edge of the clock; pin 11 (SRCLR) is the latch clock, latching data on the rising edge of the clock; and pin 8 (E) is the tri-state output control pin, outputting data when connected to a low level. Both output data and shift clock are output by the microcontroller: Data is output from port P1.0 of the microcontroller, and shifted out into the 74HC595 when the rising edge of the shift pulse arrives; port P1.1 outputs the shift pulse; and port P1.2 outputs the latch pulse. Data appearing on the parallel output terminals is driven by the 74LS245 to display the digital tube. Because the data is latched, the content of the previous data group remains unchanged when transmitting the next group of data. Data transmission and display are performed in this way; therefore, in the display module software, P1.0, P1.1, and P1.2 are all defined as analog serial ports. The keyboard interface has four keys: one set/confirm key, one modify +1 key, one modify -1 key, and one shift key. There are five LEDs corresponding to seconds, minutes, hours, countdown, and day of the week. When an LED is lit, it indicates that the corresponding second, minute, day of the week, or countdown data can be modified using the modify key. In the time setting state, first shift to the seconds digit, the corresponding seconds shift LED lights up. Press the shift key, and the shift LED will cycle through seconds → minutes → hours → countdown → weekdays. Press the modify +1 key or modify -1 key to add or subtract 1 to the data of the corresponding digit.

3. System Software Design

The system's main program includes: setting and initializing the microcontroller's serial port → reading the DS12C887 clock chip → determining whether to calculate the countdown → displaying the result. The DS12887 is initialized to a 24-hour clock, BCD code, and interrupts are not allowed. The starting address of the DS12887 is allocated as B000H, the address of register A is B00AH, the address of register B is B00BH, the address of register C is B00CH, and the address of register D is B00DH. The internal allocation of the DS12887 is shown in Table 1.

Table 1 Internal allocation of DS12887.

Internal allocation of DS12887

The display subroutine first reads data from the DS12C887 via the simulated serial port, and then displays the data using a 74HC595. The specific steps are: the display subroutine sets P1.0, sends P1.0 to the segment code, sends P1.1 to the shift pulse, sends P1.2 to the latch pulse, and returns to the main program. The countdown subroutine first reads the time unit from the DS12C887 from the microcontroller and stores it in a unit starting with 69H. During operation, it first reads the month, then uses a lookup table to calculate the number of days from the next month to the predetermined time. It then uses another lookup table to determine if the month has 31, 30, 28, or 29 days, subtracts the read date from the lookup date, and adds the two numbers to get the actual number of days. When calculating hours, minutes, and seconds, the difference can be obtained by subtracting the read hours, minutes, and seconds from the predetermined hours, minutes, and seconds. After completion, it returns to the main program.

4. Conclusion

In summary, the designed countdown system uses a DS12C887 as the clock module and an AT89C51 microcontroller to control the system. The system is configured to read data from the DS12C887 via the analog serial port and then use a 74HC595 to send the data to the digital tube display. After debugging and parameter tuning, the system operates stably and reliably, with zero accumulated error during continuous long-term operation, making it a high-precision countdown system. Practical development shows that the countdown system based on the above technology has the characteristics of compact and simple structure, low cost, and high reliability, making it easy to apply in practical applications.

Read next

Digital technology of power isolation sensors

I. Overview Power isolation sensors/transmitters are small, high-performance power testing components (products) develop...

Articles 2026-02-22
CATDOLL 128CM Cici Silicone Doll

CATDOLL 128CM Cici Silicone Doll

Articles
2026-02-22
CATDOLL 131CM Amber Silicone Doll

CATDOLL 131CM Amber Silicone Doll

Articles
2026-02-22
CATDOLL Dodo 109CM TPE

CATDOLL Dodo 109CM TPE

Articles
2026-02-22