The above is a circuit diagram. j16 is connected to j15, and J6 321 corresponds to P2 ^ 0--p2 ^ 2, which is conducive to saving MCU resources. Among them, P1 ^ 0 and Le are connected, segment selection (determines what the digital display is), and bit selection (which one of the digital tubes is bright) is determined by the 138 decoder. Let's write the program first:
# Include <reg51.h> # define uint unsigned int # define uchar unsigned char // Add code to store this in ROM; otherwise, it is stored in Ram.
// The ram bucket is small. Only 128 byteuchar code table_smg [8] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07}; uchar temp; uchar flag = 0; void inittimer0 (); void main () {int I; inittimer0 (); P1 = 0x01; temp = 0x00; while (1) {for (I = 0; I <8; I ++) {While (flag! = 1); If (flag = 1) {flag = 0; If (temp = 0x08) {temp = 0x00;} P2 = temp; p0 = table_smg [I]; temp = temp + 0x01 ;}}} void inittimer0 () {tmod = 0x01; th0 = (65536-5000)/256; tl0 = (65536-5000) % 256; et0 = 1; EA = 1; tr0 = 1;} void timer0 () interrupt 1 {th0 = (65536-5000)/256; tl0 = (65536-5000) % 256; flag ++ ;}
Pay attention to the use of latches and 138 decoders, as well as the timer interruption.
MCU Lesson 4th: timer for dynamic display of common cathode digital tube