There are two most common applications for the switching characteristics of triodes in digital circuits: One is the control application, One is the driver application. The so-called control is introduced in Figure 3-7. We can control the backlight of the rear side indirectly by controlling the base of the triode through the single-chip microcomputer. The usage is basically familiar. Another control is to control the switching between different voltages. For example, our MCU is a 5V system. It is now connected to a 12V system. If the IO is directly connected to 12V, it will burn out the MCU, so we add a triode. The working voltage of the triode is higher than the IO voltage of the MCU, and the 5V IO port is used to control the 12V circuit, as shown in Figure 3-8. Figure 3-8 Transistor voltage conversion In Figure 3-8, when the IO port outputs a high level of 5V, the triode is turned on, and the OUT output is low level 0V. When the IO port outputs a low level, the triode is turned off, and the OUT is output due to the pull-up resistor R2. The high level, thus achieving the low voltage control high voltage working principle. The so-called drive mainly refers to the current output capability. Let's look at the comparison between the two circuits in Figure 3-9. Figure 3-9 Comparison of LED small light control methods The upper LED in Figure 3-9 is the same as the LED we talked about in Lesson 2. When the IO port is high, the small light goes out. When the IO port is low, the small light is on. Then the circuit below, according to this reasoning, when the IO port is high, there should be current flowing and lighting the small lamp, but in reality it is not so simple. The MCU is mainly a control device, which has the characteristics of four or two. Just as a lever must have a fulcrum, it is necessary to support the fulcrum that the whole earth must have the strength to bear. The IO port of the MCU can output a high level, but his output current is very limited. When the normal IO port outputs a high level, it is only about tens to hundreds of uA, which is less than 1mA. Bright this LED small light or the brightness is very low, this time if we want to use high level to illuminate the LED, we can use the triode to handle it. The transistor type on our board can pass 500mA current, some The current passed by the transistor is still larger, as shown in Figure 3-10. Figure 3-10 Transistor Drive LED Small Light In Figure 3-10, when the IO port is high, the transistor is turned on. Because of the current amplification of the transistor, the c-pole current can reach mA or more, and the LED small lamp can be successfully illuminated. Although we use the low level of the IO port to directly illuminate the LED, but the IO port of the microcontroller is low, can the input current be large? I think everyone can guess this, of course not. The current capacity of the IO port of the MCU is not exactly the same. For the STC89C52, the 81 page of the official manual has an introduction to the electrical characteristics. The operating current of the whole MCU should not exceed 50mA, and the total current of a single IO port should not exceed 6mA. Even some enhanced 51 IO ports can withstand a large current, can reach 25mA, but also subject to a total current of 50mA. Then we look at the 8 LED small lights in the circuit diagram, as shown in Figure 3-11. Figure 3-11 LED circuit diagram (1) Here we have to learn to look at a knowledge point of the circuit diagram. The lines on the lower side of all the LEDs on the right side of the circuit diagram are finally connected to a black thick line. Everyone notices that this place is not actually connected together, but a The drawing of the bus, after drawing this line, indicates that this is a bus structure. All nodes with the same name are one-to-one correspondence, and other names are not the same. They are not connected together. For example, DB0 on ​​the left side and DB0 on ​​the right side of the right LED2 are connected together, and are not connected to other lines such as DB1. So let's take a look at the parts of Figure 3-11 that need to be explained now, as shown in Figure 3-12. Figure 3-12 LED circuit diagram (2) Now let's calculate the circuit diagram of 3-12, subtract the voltage drop of the LED itself from the voltage of 5V, and reduce the voltage drop between the transistors e and c. The current limiting resistor is 330 ohms, then each branch The current is about 8mA, so if the LEDs are all lit at the same time, the sum of the currents is 64mA. If you directly connect to the IO port of the MCU, then the MCU must not be able to withstand it. Even if it can withstand for a short time, it will be unstable for a long time, and even cause the MCU to burn. Some students will propose ways to increase the current limiting resistor to reduce this current. For example, if it is changed to 1K, the current is less than 3mA, and the total current of 8 channels is about 20mA. First of all, lowering the current will cause the brightness of the LED small lamp to dim. The brightness of the small lamp may not be related. But because our same circuit is connected to the digital tube, we have to talk about the digital tube to display dynamically. If the digital tube is not bright enough. If that, the visual effect will be very poor, so the method of reducing the current is not desirable. Secondly, for the single-chip microcomputer, he mainly plays the control role, the current input and output ability is relatively weak, and the total current of the 8 ports of P0 also has a certain limit, so if one or two LED small lights are observed, it can barely directly Use the IO port of the MCU to connect, but connect multiple small lights. From the perspective of actual engineering, it is not recommended to directly connect to the IO port. So what if we want to use a single-chip microcomputer to control multiple LED small lights? In addition to the triode, there are actually some driver ICs. These driver ICs can be used as buffers for the microcontroller. They are only current-driven buffers and do not have any logic control effects. For example, the 74HC245 chip used on our board, this chip is Logical does not play any other role, that is, as a current buffer, we look at its data sheet, 74HC245 stable operation at 70mA current is no problem, than the microcontroller's 8 IO port is mostly, so we can put him Connect between the small lamp and the IO port for buffering, as shown in Figure 3-13. Figure 3-13 74HC245 function chart From Figure 3-13, we will analyze, in which VCC and GND need not be said, careful students will find a 0.1uF decoupling capacitor. The 74HC245 is a bidirectional buffer. The 1-pin DIR is the direction pin. When this pin is tied high, the voltage of all B numbers on the right side is equal to the voltage corresponding to the left A number. For example, if A1 is high, then B1 is high, A2 is low, B2 is low, and so on. If the DIR pin is tied low, the effect is that the voltage on the left A number will be equal to the voltage on the right B number. Because our local control terminal is connected to the P0 port on the left side, we require B to be equal to the state of A, so the 1V pin is directly connected to the 5V power supply, that is, the high level. In Figure 3-13, there is also a row of resistors R10 to R17 which are pull-up resistors. The usage of this resistor is described later. There is also the last enable pin 19 pin OE, called output enable. There is a horizontal line on this pin, indicating that it is active low. When connected low level, 74HC245 will be bidirectional according to the above mentioned. The role of the buffer, if OE is connected to a high level, then regardless of how DIR is connected, the pins of A and B are irrelevant, that is, the 74HC245 function cannot be realized. As can be seen from Figure 3-14 below, the P0 port of the microcontroller and the A terminal of the 74HC245 are directly connected. In this place, some students have a question, that is, we have added a triode driver in the place of the power supply VCC. Why do we need to add 245 driver chips? Here we must understand the truth, the circuit from the positive electrode through the device to the ground, first must have current to work properly, any position in the circuit is disconnected, there will be no current, the device will not participate in the work. Secondly, with the water flow, the thickness of the current water pipe from the positive pole to the negative pole of the power supply must meet the requirements. If the pipe at any one position is too thin, there will be a bottleneck effect, and the current will be limited and reduced in the thin pipe in the entire passage. At each position of the circuit path, it is necessary to ensure that the channel is sufficiently clear. The role of the 74HC245 is to eliminate the bottleneck of the microcontroller IO. Figure 3-14 Connection of the MCU to the 74HC245 Area Array Sensor,Passive Infrared Detector,Infrared Heat Detector,Infrared Area Sensor Ningbo NaXin Perception Intelligent Technology CO., Ltd. , https://www.nicswir.com