1. Principle Introduction
The control circuit of the digital tube is introduced in detail in "51 Single-Chip Microcomputer (VIII)", and the hardware circuit is shown in the figure below.
In this experiment, we scan the digital tube. When conducting the experiment, you need to connect the P00~P07 pins of the microcontroller to J44. The corresponding relationship of the interface is (P00-D0), ..., (P07-D7). Connect the P10 and P11 pins of the microcontroller to J45, P10 corresponds to DM on J45, and P11 corresponds to WM.
2. Example Introduction
The code for this experiment is as follows
#include #define DATA P0 //define data port. When you encounter DATA in the program, replace it with P0 port. sbit DM = P1^0; //define latch enable port segment latch sbit WM = P1^1; //define latch enable port bit latch unsigned char BJTY_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //display segment code value 0123456789 unsigned char BJTY_WeiMa[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; // respectively correspond to the corresponding digital tube light up, that is, the bit code unsigned char m=0; /************************************************************************/ /* Delay function */ /* The calculation of delay time corresponds to the 12MHz crystal oscillator of the microcontroller */ /* x is the delay in ms, for example: when x is 10, the delay time is about 10ms */ /************************************************************************/ void delay1ms(unsigned int x) { unsigned int i,j; for(j=0;j } /************************************************************************/ /* Main function */ /************************************************************************/ void main(void) { for(;;) { DATA=0; // Clear the display to prevent ghosting DM=1; //Segment latch DM=0; DATA=BJTY_WeiMa[m]; //Get bit code WM=1; //bit latch WM=0; DATA=BJTY_DuanMa[m]; //Get segment code DM=1; //Segment latch DM=0; delay1ms(2); //delay 2ms m++; if(m==8) //Check if the 8-bit scan is finished m=0; //If the scan is completed, scan 8 bits again from the first one } } Burn the program into the microcontroller and run it. The effect is as follows. 1. Dynamic scanning is required when multiple digital tubes are needed to display different data. The scanning method is to light up the first digit of the digital tube first, then the second digit, and then light up the other digits. After lighting up the eighth digit, turn back to light up the first digit, and repeat this process. The dynamic scanning speed is very fast. Due to the visual persistence of the human eye, the effect seen is that all eight digital tubes are lit at the same time. The so-called "visual persistence" means that when the human eye observes the scene, the light signal is transmitted to the brain nerves for a short period of time. After the light effect ends, the visual image does not disappear immediately. This residual vision is called "afterimage", and this visual phenomenon is called "visual persistence". It can be seen from the program that after assigning a bit of data to the digital tube, there is a delay of 2ms. delay1ms(2); //delay 2ms It takes a total of 16ms to display 8 bits of data, and the visual persistence time of the human eye is about 100ms. Therefore, although only one digital tube is lit at a single moment, the effect seen by people is that all 8-bit digital tubes are lit and display different numbers. 2. If statement In this program, the if statement is used. if(m==8) //Check if the 8-bit scan is finished m=0; //If the scan is completed, scan 8 bits again from the first one The function of this if statement is to determine whether m is equal to 8. If so, the eighth digital tube is lit up, then m=0 is set, and the first digital tube is lit up in the next cycle. The if statement can form a branch structure. It judges based on the given conditions to decide to execute a branch program segment. There are three basic forms of the if statement in C language. The first form is the basic form: if(expression) Statements Its semantics is: if the value of the expression is true, the following statement is executed, otherwise the statement is not executed. The process can be represented as the following figure. The second form is: if-else if(expression) Statement 1; else Statement 2; Its semantics is: if the value of the expression is true, statement 1 is executed, otherwise statement 2 is executed. The process can be represented as the following figure. The third form is the if-else if-else form The first two forms of if statements are generally used in situations with two branches. When there are multiple branch choices, you can use if-else if-else statements, which are generally in the form of: if(expression1) Statement 1; else if(expression 2) Statement 2; else if(expression 3) Statement 3; … else if (expression m-1) Statement m-1; else statement m; Its semantics is: judge the value of the expression in turn, and when a value is true, execute the corresponding statement. Then jump out of the entire if statement and continue to execute the program. If all expressions are false, execute statement m. Then continue to execute the subsequent program. The execution process of if-else if-else statement is shown in the figure below. For the operation code of the latch, please refer to the explanation in "51 Single-Chip Microcomputer (Part 9)".
Previous article:51 Single Chip Microcomputer (XI)—— 8-bit Digital Tube-4-bit Accumulation
Next article:51 Single Chip Microcomputer (Part 9) - 8-bit Digital Tube - Display one bit
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- MicroPython Hands-on (15) - AB Buttons on the Control Panel
- TMS320F28335---External key interrupt
- UCD9090A-How to use TI power sequencer in 5G MIMO applications
- Is FPGA acceleration of CNN an option? What board should I use?
- Security Tools Bombercat
- The solid state drive doesn't seem to be as good as I thought
- [NXP Rapid IoT Review] Local compilation of online generated projects
- EEWORLD University ---- Practical Guide to Motor Application Development - Based on STM32
- Simulation Help Post
- Based in Chengdu, job position: Reliability Engineer