The circuit diagram of the digital tube module of the development board is as follows:
Due to the characteristics of the 74ls138 decoder, that is, only one digital tube can have a cathode level of 0, it is obviously impossible to make multiple digital tubes work at the same time. If you want to get the effect of multiple digital tubes working at the same time, you can only use the dynamic scanning display method. The so-called dynamic scanning display is to use the afterglow of the light-emitting tube and the visual persistence of the human eye to make people feel as if multiple digital tubes are working at the same time.
In the program, the digdisplay function uses for loops and switch statements to continuously scan the 8 digital tubes, complete the bit selection, and assign values to the P0 port to realize the segment selection function. Thus, the 8 digital tubes output 1 to 8 in sequence, and use the delay function to control the output interval time to realize the dynamic output function.
detail:
(1) Set a certain delay after each digital tube displays.
(2) Set P0 to 0 (P0 = 0x00) to achieve the purpose of "erasing the image".
#include #define uc unsigned sbit lsc=P2^2; sbit lsb=P2^3; sbit lsa=P2^4; void delay(uc n) { uc i,j; for(i=1;i<=n;i++) for(j=110;j>=1;j--); } uc code x[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f, 0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; void digdisplay() { uc i; for(i=1;i<=8;i++) { switch(i) { case (1): lsa=0,lsb=0;lsc=0;break; case (2): lsa=0,lsb=0;lsc=1;break; case (3): lsa=0,lsb=1;lsc=0;break; case (4): lsa=0,lsb=1;lsc=1;break; case (5): lsa=1,lsb=0;lsc=0;break; case (6): lsa=1,lsb=0;lsc=1;break; case (7): lsa=1,lsb=1;lsc=0;break; case (8): lsa=1,lsb=1;lsc=1;break; } P0=x[i]; delay(1); P0=0x00; } } void main() { while(1) { digdisplay(); } } Advanced: Use digital tubes to output different digital combinations at intervals. #include #define uc unsigned char sbit lsa=P2^2; sbit lsb=P2^3; sbit lsc=P2^4; uc code x[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f, 0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; void delay1(uc n) { uc i,j; for(i=1;i<=n;i++) for(j=1;j<=110;j++); } void digdisplay(int n) { uc i; if(n==1) { for(i=0;i<3;i++) { switch(i) { case(0): lsc=0;lsb=0;lsa=0; P0=x[0];break; case(1): lsc=0;lsb=0;lsa=1; P0=x[2];break; case(2): lsc=0;lsb=1;lsa=0; P0=x[5];break; } delay1(1); } } else { for(i=0;i<4;i++) { switch(i) { case(0): lsc=0;lsb=0;lsa=0; P0=x[4];break; case(1): lsc=0;lsb=0;lsa=1; P0=x[1];break; case(2): lsc=0;lsb=1;lsa=0; P0=x[3];break; case(3): lsc=0;lsb=1;lsa=1; P0=x[1];break; } delay1(1); } } } void delay2(uc n) { uc i,j; for(i=1;i<=10;i++) for(j=1;j<=110;j++) digdisplay(n); } void main() { while(1) { delay2(1); delay2(0); } }
Previous article:51 MCU Experiment 4: Static Digital Tube
Next article:STC89C52 series MCU internal resources - interrupt system
- Popular Resources
- Popular amplifiers
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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Detailed analysis of static in C language
- Using MicroPython on Lego EV3
- 【Showing goods】The third wave
- High-speed DAC
- Aperture Tuning: An Essential Technology in 5G Smartphones
- 【RT-Thread Reading Notes】5 Chapter Reading Notes
- FPGA_100 Days Journey_AD Design
- What are some reasons why low-power op amps use pulsed power?
- Pingtouge RVB2601 board-SPI test
- LCD refresh problem