Digital tube dynamic display
Static and dynamic display
dynamic display
The characteristic of dynamic display is that the segment selection lines of all digital tubes are connected in parallel, and the bit selection lines control which digital tube is effective. The selected digital tube adopts dynamic scanning display. The so-called dynamic scanning display is to send glyph codes and corresponding bit selections to each digital tube in turn. It uses the afterglow of the luminescent tube and the persistence of human vision to make people feel as if all the digital tubes are displaying at the same time.
Array definition and reference
An array is a collection of ordered data, and each data in the array is of the same data type. Elements in an array can be uniquely identified by the array name and subscript.
The general format of an array is defined as follows:
Data type array name [constant expression] = {element list};
For example:
unsigned char tabel[3] = [0x3F, 0x06, 0x5B,];
P0 = tabel[0]; //The value of P0 at this time is 0x3F
Digital tube dynamically displays the number 123
#include #include #define uint unsigned int #define uchar unsigned char sbit DU = P2^6;//digital tube segment selection sbit WE = P2^7;//Nigital tube segment selection // Millisecond delay function definition void delay(uint z){ // Millisecond delay function definition uint x, y; for (x = z; x > 0; x--){ for (y = 114; y > 0; y--){ } } } void main(){ // The main function itself will loop while(1){ /*The first digit displayed is 1*/ P0 = 0XFF; // Clear the broken code. If the value 0XFF is not initialized for P0, then the value of P0 will be the value assigned in the previous process of opening the segment selection latch. When executed here, the segment selection value will be assigned to P0 in the latch. , causing the digital tube to display errors. WE = 1; //Open bit select latch P0 = 0XFE; // 1111 1110 strobe the first digital tube // P0 = 0X00; // 0000 0000 means strobing all digital tubes WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = 0X06; // 0000 0110 displays "1" DU = 0; //Latch segment selection data delay(5); // Perform a 5 millisecond delay operation for each digital tube switching /*The second digit displays number 2*/ P0 = 0XFF; // Clear break code WE = 1; //Open bit select latch P0 = 0XFD; // 1111 1101 strobe the second digital tube // P0 = 0X00; // 0000 0000 means strobing all digital tubes WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = 0X5B; // 0101 1011 displays "2" DU = 0; //Latch segment selection data delay(5); /*The third digit displays the number 3*/ P0 = 0XFF; // Clear break code WE = 1; //Open bit select latch P0 = 0XFB; // 1111 1011 strobe the third digital tube // P0 = 0X00; // 0000 0000 means strobing all digital tubes WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = 0X4F; // 0100 1111 displays "3" DU = 0; //Latch segment selection data delay(5); } } Digital tube dynamically displays the number 123 (code optimization) #include #include #define uint unsigned int #define uchar unsigned char sbit DU = P2^6;//digital tube segment selection sbit WE = P2^7;//Nigital tube segment selection //Common cathode digital tube segment selection table 0-9 uchar code tabel[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,}; /*==================================== Function : delay(uint z) Parameter : z delay millisecond setting, value range 0-65535 Return value : None Description : 12T/Fosc11.0592M millisecond delay ====================================*/ void delay(uint z) { uint x,y; for(x = z; x > 0; x--) for(y = 114; y > 0; y--); } /*==================================== Function : display(uchar i) Parameter : i displays the numerical value, the value range is 0-255 Return value : None Description : Three-digit common cathode digital tube dynamic display ====================================*/ void display(uchar i) { uchar bai, shi, ge; bai = i / 100; //236 / 100 = 2 shi = i % 100 / 10; //236 % 100 / 10 = 3 ge = i % 10;//236 % 10 =6 //The first digital tube P0 = 0XFF;//Clear broken code WE = 1;//Open bit selection latch P0 = 0XFE; //1111 1110 WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[bai];// DU = 0; //Latch segment selection data delay(5); //The second digital tube P0 = 0XFF;//Clear broken code WE = 1;//Open bit selection latch P0 = 0XFD; //1111 1101 WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[shi];// DU = 0; //Latch segment selection data delay(5); //The third digital tube P0 = 0XFF;//Clear broken code WE = 1;//Open bit selection latch P0 = 0XFB; //1111 1011 WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[ge];// DU = 0; //Latch segment selection data delay(5); } void main()//main function itself will loop { while(1) { display(123); //Nigital tube display function } } The digital tube dynamically displays the number 12345678 (code optimization) #include #include #define uint unsigned int #define uchar unsigned char sbit DU = P2^6;//digital tube segment selection sbit WE = P2^7;//Nigital tube segment selection //Common cathode digital tube segment selection table 0-9 uchar code tabel[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,}; /*==================================== Function : delay(uint z) Parameter : z delay millisecond setting, value range 0-65535 Return value : None Description : 12T/Fosc11.0592M millisecond delay ====================================*/ void delay(uint z) { uint x,y; for(x = z; x > 0; x--) for(y = 114; y > 0; y--); } /*==================================== Description : Eight-bit common cathode digital tube dynamic display ====================================*/ void display(uchar num1, uchar num2, uchar num3, uchar num4, uchar num5, uchar num6, uchar num7, uchar num8) { /*Display the first position*/ P0 = 0XFF;//Clear broken code WE = 1;//Open bit selection latch P0 = 0XFE; //1111 1110 WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num1];// DU = 0; //Latch segment selection data delay(1); /*The second digit is displayed*/ P0 = 0XFF;//Clear broken code WE = 1;//Open bit selection latch P0 = 0XFD; //1111 1101 WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num2];// DU = 0; //Latch segment selection data delay(1); /*The third digit is displayed*/ P0 = 0XFF;//Clear broken code WE = 1;//Open bit selection latch P0 = 0XFB; //1111 1011 WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num3];// DU = 0; //Latch segment selection data delay(1); /*The fourth digit is displayed*/ P0 = 0XFF; // Clear break code WE = 1; //Open bit select latch P0 = 0XF7; // 1111 0111 strobe the fourth digital tube WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num4];// DU = 0; //Latch segment selection data delay(1); /*fifth digit display*/ P0 = 0XFF; // Clear break code WE = 1; //Open bit select latch P0 = 0XEF; // 1110 1111 strobe the fifth digital tube WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num5];// DU = 0; //Latch segment selection data delay(1); /*The sixth digit is displayed*/ P0 = 0XFF; // Clear break code WE = 1; //Open bit select latch P0 = 0XDF; // 1101 1111 strobe the sixth digital tube WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num6];// DU = 0; //Latch segment selection data delay(1); /*The seventh digit is displayed*/ P0 = 0XFF; // Clear break code WE = 1; //Open bit select latch P0 = 0XBF; // 1011 1111 strobe the seventh digital tube WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num7];// DU = 0; //Latch segment selection data delay(1); /*Eighth digit display*/ P0 = 0XFF; // Clear break code WE = 1; //Open bit select latch P0 = 0X7F; // 0111 1111 strobes the eighth digital tube WE = 0; //Latch bit selection data DU = 1; //Open segment selection latch P0 = tabel[num8]; DU = 0; //Latch segment selection data delay(1); } void main()//main function itself will loop { while(1) { display(1, 2, 3, 4, 5, 6, 7, 8); //Nigital tube display function } }
Previous article:STC89C52 microcontroller independent keyboard
Next article:STC89C52 microcontroller digital tube static display
Recommended ReadingLatest update time:2024-11-16 13:03
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Smart MM32F0270 timer DMA mode output PWM
- If the input power may be 12V or 24V, how should the TVS diode be selected?
- About Lithium Battery Pack Monitoring, SOC and Battery Balancing Technology
- I am going to make a USB sound card myself and give a few to the forum.
- About the font design of single chip microcomputer
- Free evaluation: Pengfeng perf- V fpga development board worth thousands of yuan
- How to use IAR V7.12.1 to program MSP430 series microcontrollers
- sampling
- HuaWei Verilog Constraints
- ESP32 development environment: IDF, Eclipse, vscode simple installation