
We use a real timer clock circuit to illustrate the method of software programming, the clock is our most common display hours, minutes, seconds, timing tool, it is
representative of typical applications.
The minimum time the clock is in seconds, but the use of microcontroller timer for timing, the use of 6.0MHz crystal, and even by way of a job of work,
the maximum time to time can only 131ms, so we can time the time of each take 125ms, so the timer overflow 8 (125ms * 8 = 1000ms) to be the smallest time unit
of seconds. In order to achieve 8 count method implementation in software is easy.
We use Timer 1 to work a job, time 125ms timer. Overflow interrupt method using the cumulative number of times, when the expiry of 8 times that by 1 second of time.
Cumulative time of a clock, to achieve the points, when the carry, to use a variety of hex, seconds, minutes, hours in the binary decimal, decimal seconds to minutes and minutes to when it is six decimal carry, every day another twelve hours or twenty-hour clock system, which is ten, respectively, binary and hexadecimal round. From seconds to hours and hours assigned by the software from the cumulative realized and numerical comparison.
In the MCU's internal RAM, the need to set the display buffer to display the hours, minutes and seconds value is removed from the display buffer, in RAM, set of four units as the display buffer, respectively, 7AH, 7BH, 7CH. In order to describe the circuit and the principles of convenience, we here do not show seconds values, we carry a second score achieved by flashing. So we were a total of four LED display and score. At the same time the clock will need calibration. Shown in the program code needed to set the table, the value to be displayed will be displayed through the table read instruction used in the real code value to the LED. We use the PP3.4 AT89C2051 microcontroller and the P3.5 two I / O port external micro switch to achieve the correct hours and minutes, hours or score every time plus 1, the cumulative value of continuous press down to achieve the clock calibration.
In the circuit, we also set up a buzzer, for simple timekeeping use, such as can be set to get up at 7:30 am, 1:30 timekeeping get up again, each time one minute ring, ring 1 second, stop 2 seconds, rather than a continuous ring. The program we use 12-hour system, do this, set in the program corresponding to the symbol of the main program in order to facilitate identification. The same time the program will have several related marks, mainly the steering control program flow. Program we have made a more detailed comments, no further explanation.
Hardware circuit, we were still low-cost micro-processing unit for the AT89C2051 microcontroller, the chip compatible with C51 instruction set, to write the program in the C51, without any modification can be easily ported to the chip up. P0 port as our field bit LED driver output, a second "carry" prompted by scores of flickering, bright 0.5 seconds, 0.5 seconds off. , P3.1-P3.3 for-bit driver, the use of dynamic scanning display, the display time of each LED among 10-25ms can, scanning frequency not too high or the time each had a short LED display brightness too low, not easy to watch, to the naked eye does not feel is appropriate LED flashes. For intuitive, we did not use the drive output of integrated circuits, but the use of discrete components - transistors, but the principle is the same.
The decision circuit using common anode LED digital tube, can be used LQ5101BS ordinary light-emitting diode, drive transistor can be easy to get the 2SA1015 and 2SC1815 and other models, of course, can also be used as the S9012, S9013, S9014, 2N5401, 2N5555 and other small power transistor, other devices have no special requirements. For experiments, can be DIP20P AT89C2051 microcontroller socket After programming, debugging error-free, can be programmed into the AT89C2051, it is worth mentioning that, AT89C2051 is a Flash program memory, the program can be repeatedly erased, for the experiment is very convenient.