1. Dynamic digital tube principle:
First, a schematic diagram:
The digital tube is actually composed of multiple LEDs (the decimal point is also one), as shown in the picture above, an 8 plus a decimal point is a digital tube, a total of eight LEDs, and the picture above shows eight digital tubes.
Digital tubes can be divided into common cathode and common anode digital tubes according to different connection methods. Literally, common cathode means the cathodes of the eight segments of a digital tube are connected together, and common anode means the anodes of the eight segments of a digital tube are connected together.
I would like to state that my digital tube is common cathode.
Below are two static digital tubes (I think the dynamic digital tube is to remove the GND and VCC in the two pictures below and connect them to other tube ports):
Common cathode:
Common Anode:
The upper right corner is 5v, which is the VCC high voltage
As long as the voltage of a~g and dp is controlled, the brightness of the LED can be controlled.
The dynamic digital tube is different. For example, there are eight digital tubes in the first picture. If they are all like static digital tubes, 8×8=64 tube ports will be needed to control them. Therefore, the dynamic digital tube uses the dynamic scanning principle to achieve the purpose of lighting different numbers (or letters: A, b, C, d, E, F) on different digital tubes.
Dynamic scanning, as the name suggests, means scanning, which means that one digital tube lights up one at a time, but because the human eye has persistence of vision, as long as the lighting period is short enough through appropriate delay so that the previous digital tube is still bright in our eyes when the next digital tube lights up, our goal can be achieved - they light up together.
In this way, we can use eight ports to control which digital tube is lit, and use eight ports to control which LED segments of the digital tube are lit. A total of 16 ports are used, which greatly reduces the number of ports required. In addition, with a 38 decoder, 3 channels of input, and 8 channels of output, only 3+8=11 ports are needed to control eight digital tubes.
There are two concepts here, segment selection and bit selection.
Position selection: "Position", as the name suggests, selects which position of the digital tube to light up.
Segment selection: "Segment", select which "segments" of the selected digital tube will light up.
From the schematic diagram given at the beginning, we can see that the eight ports of P0 control the segment selection (it is easy to see which port controls which LED segment from the diagram). The purpose of passing through D74HC245 first is to increase the drive. If the current of the microcontroller is not enough, the digital tube will be very dim (some people say that the current of the common cathode will not be enough, and the common anode can be driven directly. I don't understand it. I need to check it out). If you want to know which port of the microcontroller controls the bit selection, there is another picture:
Based on the previously known functions of this chip, we can control the input values of P2^2, P2^3, and P2^4 to control which of Y0 (upper horizontal line) to Y7 (upper horizontal line) outputs low voltage. The digital tube connected to the port that outputs low voltage is selected.
If you want the digital tube to light up, you must input a high voltage on the segment selector to determine the value of the P0 port.
2. Dynamic digital tube programming:
#include sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; unsigned int code smgduan[16]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; // Common cathode digital tube table, corresponding to the digital tube display 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, d, E, F; This is the array definition and initialization in C language void delay(unsigned int i) //custom function delay { while(i--); } void bigdisplay() //Custom function bigdisplay { unsigned int i; for(i=0;i<8;i++) //for statement in C language { switch(i) //C language switch statement , here is to deal with the problem of which digital tube is lit - bit selection { case 0:LSA=0,LSB=0,LSC=0;break; //The value of i is the same as that of the case, which statement will be executed, and then the output state of the 38 decoder can be known from the truth table, and finally which digital tube will be lit (the thinking direction is opposite to this when programming) case 1:LSA=1,LSB=0,LSC=0;break; case 2:LSA=0,LSB=1,LSC=0;break; case 3:LSA=1,LSB=1,LSC=0;break; case 4:LSA=0,LSB=0,LSC=1;break; case 5:LSA=1,LSB=0,LSC=1;break; case 6:LSA=0,LSB=1,LSC=1;break; case 7:LSA=1,LSB=1,LSC=1;break; } P0=smgduan[i]; //Assign a value to P0, the value is the i-th number in the smgduan array above, note: start counting from 0; usage of arrays in C language; if i in this statement is replaced with i+8, the final effect diagram is as follows. delay(100); //Call the delay function to delay, the delay should not be too short or too long P0=0x00; //P0 is reset to zero, otherwise there will be interference when lighting the second digital tube, resulting in ghosting } } void main() //Main function { while(1) // 1 always meets the loop condition and keeps looping the statements in {} { bigdisplay(); //Call the function bigdisplay compiled above. If you do not customize the function bigdisplay, you can also write the program directly in the main function main } } Effect: 1. Original code: 2. After replacing the i specified in the above code: Remember to read from right to left
Previous article:Independent keys of Xiaobai's self-study C51 notes
Next article:Xiaobai's self-study notes on C51 digital tube 1——D74HC245 and D74HC138
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- Free shipping! New FPGA core board (with power cord)
- Ideal filter is not achievable
- Model-Based Design Helps Unleash the Potential of Software-Defined Radio
- A factory in Shenzhen closed down, and got a batch of WIFI air conditioner microcontrollers. Students who like research can tinker with them.
- A Simple Introduction to LPC9401 Flash MCU
- What is the relationship between the switching current and the maximum output current of a switching power supply?
- This is the best neural network I have ever seen.
- PCB design considerations
- [NXP Rapid IoT Review] Finally received it, routine unboxing
- Intelligent safety system makes safety "smart"