The switching characteristics of transistor in digital circuit, the most common applications are 2: one is control application, the other is drive application.

  The so-called control is basically familiar, that is, we can control the base of the transistor through the single chip microcomputer to indirectly control the light off of the small lights behind. There is also a control is the conversion control between different voltages, for example, our MCU is a 5 V system, it now has to connect with a 12 V system, if the IO directly connected to 12 V voltage will burn out the MCU, so we add a transistor.


  When the IO port outputs a high level of 5 V, the transistor is switched on and outputs a low level of 0. When the IO port outputs a low level, the transistor ends and the OUT outputs a high level of 12 V due to the pull-up resistance. This realizes the working principle of low voltage control and high voltage.

  The so-called drive, mainly refers to the current output capacity. When the IO port is high, the small lamp goes out, when the IO port is low, the small lamp lights up. And the lower circuit, according to this reasoning, when the IO port is high, there should be a current flowing through and a small lamp lit, but in fact it is not so simple.


  Single-chip microcomputer is mainly a control device, with the characteristics of four or two thousand jin. Just as leverage must have a fulcrum, it must have a fulcrum to support the whole earth. The IO port of a single chip microcomputer can output a high level, but its output current is very limited. When the ordinary IO port outputs a high level, there are only tens to hundreds of uA of current, less than 1 mA, and the LED light or low brightness.

  When the IO port is high and the transistor is on, because of the current amplification of the transistor, the c current can reach more than mA, and the small lamp can be lit successfully.


  While we use the low level of the IO port to light LED, directly But the MCU IO as a low level, Can the input current be large? I think everybody can guess this, Of course not. SCM IO current bearing capacity, Different models are different, For STC89C52, The 81 pages of the official manual contain an introduction to electrical characteristics, The working current of the whole MCU, Do not exceed 50 mA, The total current at a single IO port should not exceed 6 mA. Even if some of the IO ports of the enhanced 51 bear a little more current, 25 mA, But it is also limited by a total current of 50 mA. Then let's look at the circuit diagram of the eight LED lights this part of the circuit.

  Here we have to learn to read a knowledge of the circuit diagram, All the LED lines on the right side of the circuit diagram are finally connected to a black thick line, Attention, This place isn't actually completely connected, It's a bus painting, After drawing this line, Indicates that this is a bus structure. And all nodes with the same name are connected one by one, Different names, Is not connected. Like the DB0 on the left and the LED2 light on the right, And other lines such as DB1 are not connected. Now let's go through the 3-12 circuit diagram, 5V voltage minus LED own voltage drop, Reduce the pressure drop between the transistor e and the c, The current limiting resistance is 330 Euro, And the current of each branch is about 8 mA, So 8 LED if all lights up at the same time, the sum of the current is 64 mA. If this is directly connected to the MCU IO port, That MCU must not bear, Even in a short time, Long hours of work are unstable, Even lead to single-chip computer burning.


  Some people will come up with ways to increase the current limiting resistance to reduce the current. Such as change to 1 K, then the current less than 3 mA,8 the total current is about 20 mA. First of all, reducing the current will cause the brightness of the LED lamp to darken, the brightness of the lamp may not matter, but because our same circuit is connected to the digital tube, we have to talk about the digital tube dynamic display, if the digital tube brightness is not enough, the visual effect will be poor. Secondly, for the single-chip microcomputer, he mainly plays a control role, the ability of current input and output is relatively weak, and the total current of P0 8 ports is also limited, so if one or two LED lights are observed, You can barely connect with the IO port of the MCU. So if we want to use single-chip computer to control multiple LED lights how to do?There are some drivers in addition to the Triode IC, which can be used as the buffer of the single chip microcomputer, only the current drive buffer, does not play any logical control effect, such as the 74 HC245 chip used on our board. This chip does not function logically as a current buffer. By looking at its data manual ,74 HC245 stable working at 70 mA the current is no problem, much more than the 8 IO ports of the single chip microcomputer, And so we can put him between the light and the IO mouth


  74HC245's a bidirectional buffer, 1 pin DIR direction pin, When this pin is high, The voltage of all B numbers on the right is equal to the voltage corresponding to the left A number. For example, A1 is high, And then B1 is high, A2 is low, B2 is low level and so on. If DIR pin is low, The effect is that the voltage of the left A number will be equal to the voltage corresponding to the right B number. Because we have a P0 port on the left, We ask B to be equal to A, And that's why we have five V of power, That is, high level. There is also a row of resistance R10 to R17 pull up resistance, The use of this resistance is introduced later.

  There is also the last enable pin 19 pin OE, called output enable, this pin has a horizontal, indicating that the low level is effective, when the low level is connected ,74 HC245 will play the role of two-way buffer, if the OE is connected to the high level, No matter how the DIR is connected, A and B pins have nothing to do with the 74 function.


  The P0 port of single chip microcomputer and the A end of 74 HC245 are connected directly. Here, there is a question, that is, we clearly added a transistor drive in the power VCC, why add 245 drive chip. Here RenhotecIC we need to understand a truth, the circuit from the positive electrode to the ground, the first must have a current to work properly, any position in the circuit disconnected, there will be no current, the device will not participate in the work. Secondly, according to the flow of water, the thickness of the current pipe from the positive to the negative electrode of the power supply should meet the requirements. Therefore, in every position of the circuit path, the channel should be smooth enough. The function of this 74 HC245 is to eliminate the bottleneck of MCU IO this link.