Commonly used interface circuits and their programming[Copy link]
Connection and programming of LED digital display
In the single-chip microcomputer system, LED digital display is usually used to display various numbers or symbols. It is widely used because of its clear display, high brightness, low voltage and long life.
Eight-segment LED display
Introduction: Do you remember the "matchstick game" we played when we were young? Several matchsticks can be combined into various shapes. The LED display is actually such a thing.
The eight-segment LED display is composed of 8 light-emitting diodes. Among them, 7 long strips of light-emitting diodes are arranged in the shape of a "日", and another dot-shaped light-emitting diode is used as a decimal point in the lower right corner of the display. It can display various numbers and some English letters. There are two different forms of LED displays: one is that the anodes of the 8 light-emitting diodes are connected together, which is called a common anode LED display; the other is that the cathodes of the 8 light-emitting diodes are connected together, which is called a common cathode LED display. As shown in the figure below. The names and arrangement positions of the stroke segments of the LED displays with common cathode and common anode structures are the same. When the diode is turned on, the corresponding stroke segment lights up, and various characters are displayed by combining the illuminated stroke segments. The 8 stroke segments hgfedcba correspond to a byte (8 bits) of D7 D6 D5 D4 D3 D2 D1 D0, so the 8-bit binary code can be used to represent the font code of the character to be displayed. For example, for a common cathode LED display, when the common cathode is grounded (zero level) and the anode hgfedcba segments are 0111011, the display displays the character "P", that is, for a common cathode LED display, the glyph code of the character "P" is 73H. If it is a common anode LED display, the common anode is connected to a high level, and the glyph code for displaying the character "P" should be 10001100 (8CH). It must be noted here that many products, for the convenience of wiring, often do not follow the rules to correspond to the relationship between fields and bits. In this case, the glyph code must be designed according to the wiring. We will give an example later.
1. Static display interface In the single-chip microcomputer application system, there are two common display methods: static display and dynamic scanning display. The so-called static display means that each display must occupy a separate I/O interface with a latching function for the stroke segment glyph code. In this way, the single-chip microcomputer only needs to send the glyph code to be displayed to the interface circuit, and then it will not care about it until new data is to be displayed, and then send the new glyph code. Therefore, using this method, the CPU overhead in the single-chip microcomputer is small. There are many I/O interface circuits that can provide separate latches. Here, taking the commonly used serial-to-parallel conversion circuit 74LS164 as an example, a commonly used static display circuit is introduced to give everyone a certain understanding of static display. The serial port mode of the MCS-51 single-chip microcomputer is replaced by the shift register mode. Six external 74LS164s are used as the static display interface of the 6-bit LED display. The RXD of 8031 is used as the data output line and the TXD is used as the shift clock pulse. The 74LS164 is a TTL unidirectional 8-bit shift register that can realize serial input and parallel output. Among them, A and B (pins 1 and 2) are serial data input terminals. The two pins input signals according to the logic and operation rules. They can be connected in parallel when there is a common input signal. T (pin 8) is the clock input terminal, which can be connected to the TXD terminal of the serial port. When the rising edge of each clock signal is added to the T terminal, the shift register shifts one bit. After 8 clock pulses, all 8-bit binary numbers are shifted into 74LS164. R (pin 9) is the reset terminal. When R=0, each bit of the shift register is reset to 0. Only when R=1, the clock pulse works. The parallel output terminals of Q1...Q8 (pins 3-6 and 10-13) are connected to the corresponding pins of each segment of hg---a of the LED display. The following can also be introduced about 74LS164: the so-called clock pulse end actually requires high, low, high, low pulses, no matter how the pulse comes from. For example, we use a wire, one end is connected to T, and the other end is held by hand, and connected to high level and low level respectively, which is also to give a clock pulse. At the moment when 74LS164 obtains the clock pulse (to be clear, it is at the edge of the pulse), if the data input end (pins 1 and 2) is high, then a 1 will enter the inside of 74LS164, and if the data input end is low, then a 0 will enter its inside. After giving 8 pulses, the first data that first enters 74LS164 reaches the highest bit, and then what will happen with another pulse? With another pulse, the first pulse will be moved out from the highest bit, just like queuing to buy tickets at the station, the railing is so long, and if one person wants to enter from the back, one person must walk out from the front. After clarifying this, let's look at the circuit. Six 7LS164s are connected end to end, and the clock ends are connected together. In this way, when 8 pulses are input, the data output from the RXD end of the microcontroller enters the first 74LS164, and when the second 8 pulses arrive, this data enters the second 74LS164, and the new data enters the first 74LS164. In this way, when the sixth 8 pulses are completed, the first data sent is sent to the leftmost 164, and the other data appears in the first, second, third, fourth, and fifth 74LS164 in turn. There is a question. When the first pulse arrives, except for the first 74LS164 receiving data, what are the other chips doing? They are also receiving data because their clock ends are connected together, but the data has not been sent to the other chips. What data are they receiving? . . . . . . . . In fact, the so-called data is just a way of saying it. It actually refers to the level. When the first pulse arrives, the first 164 receives data from the microcontroller, and the other chips are also connected to Q8 of the previous chip. Q8 is a wire. In digital circuits, it can only have two states: low level or high level, that is, "0" and "1". So the next 74LS164 is also receiving data. It's just that all it receives is 0 or 1. This question is explained here. Some friends may be dismissive, while some friends may still not understand. This actually involves the nature of numbers. If you don't understand, please think carefully, find some numbers of digital circuits, understand the working principle of 164, and then look at this question, or read my other article "Concepts that are easy to grasp for beginners of microcontrollers".
Be sure to understand this. Once you understand this, your level will be higher than that of a beginner.
Entry: Put the numbers to be displayed in the display buffer 60H-65H, a total of 6 units, and correspond to each digital tube LED0-LED5. Exit: Convert the 6 numbers preset in the display buffer into corresponding display glyph codes, and then output them to the display for display. The display program is as follows: DISP: MOV SCON,#00H; Initialize serial port mode 0 MOV R1,#06H; Display 6 digits MOV R0,#65H; 60H-65H is the display buffer MOV DPTR,#SEGTAB; Entry address of font table LOOP: MOV A,@R0; Get the highest bit of data to be displayed MOVC A,@A+DPTR; Look up the table to get the font code MOV SBUF,A; Send to serial port display DELAY: JNB TI,DELAY; Wait for the transmission to be completed CLR TI; Clear the transmission flag DEC R0; The pointer moves down one bit, ready to take the next number to be displayed DJNZ R1,LOOP; Until all 6 data are displayed. RET SETTAB:; The font table has been introduced before, and we will introduce the creation of the font table later. DB 03H 9FH 27H 0DH 99H 49H 41H 1FH 01H 09H 0FFH ; 0 1 2 3 4 5 6 7 8 9 Main program for blanking code test ORG 0000H AJMP START ORG 30HSTART: MOV SP,#6FH MOV 65H,#0 MOV 64H,#1 MOV 63H,#2 MOV 62H,#3 MOV 61H,#4 MOV 60H,#5 LCALL DISP SJMP $ If the digital tubes are arranged as shown, the main program above will display 543210. Think about it, how to send the number if you want to display 012345? Let's analyze the problem of making the font table. Let's take a look at the above "standard" graphics. Write out the corresponding relationship between data bits and glyphs and list them in a table as follows (set to common positive type, that is, the pen segment is bright when the corresponding output bit is 0)
Data bits
D7
D6
D5
D4
D3
D2
D1
D0
Glyph Code
Pen level
A
B
C
D
AND
F
G
H
0
0
0
0
0
0
0
1
1
03H
1
1
0
0
1
1
1
1
1
9FH
2
0
0
1
0
0
1
1
1
27H
3
0
0
0
0
1
1
0
1
0DH
4
1
0
0
1
1
0
0
1
99H
5
0
1
0
0
1
0
0
1
49H
6
0
1
0
0
0
0
0
1
41H
7
0
0
0
1
1
1
1
1
1FH
8
0
0
0
0
0
0
0
1
01H
9
0
0
0
0
1
0
0
1
09H
How about it? You can make a glyph table, right? Just make a table and write the corresponding 0 and 1 according to the requirements (0 is on or 1 is on), and you are done. Do an exercise and write the glyph code of AF. If the order of wiring is disrupted for the convenience of wiring, how should the glyph table be connected? It is also very simple, just list it in the same way. Take the new experimental board as an example, common anode type. The wiring is as follows: P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0C EHDGFAB Then the font code is as follows: 0 00101000 28H; 1 01111110 7EH; 2 10100100 0A4H; 3 01100100 64H; 4 01110010 72H; 5 01100001 61H; 6 00100001 21H; 7 01111100 7CH; 8 00100000 20H; 9 01100000 60H As an exercise, you can write out the font code of AF. Originally, this is to explain the static interface of the display, which should be the end, but I would like to talk a little more about the nature of the number mentioned above. There are some terms and nouns in the microcontroller that are supposed to help us understand things, but sometimes we are confused by the relevant semantics of these terms, so that we cannot further recognize their essence, and thus often fall into a state of confusion. Only by deeply understanding the working characteristics of 74LS164 can we truly understand what serial data is.