Display "12345678"
P1 port connects to the segment pole of 8-link common cathode digital tube SLED8: P1.7 connects to segment h, ..., P1.0 connects to segment a
P2 port connects to the segment pole of 8-link common cathode digital tube SLED8: P2.7 connects to the common cathode on the left, ..., P2.0 connects to the common cathode on the right
Solution description: Crystal oscillator frequency fosc = 12MHz, digital tube uses dynamic refresh mode to display, implemented in 1ms timer service program
Code
1. #include
2. unsigned char DisBuf[8]; //Global display buffer, DisBuf[0] corresponds to the right SLED, DisBuf[7] corresponds to the left SLED,
3. void DisplayBrush(void)
4. { code unsigned char cathode[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; // cathode control code
5. Code unsigned char Seg7Code[16]= //Use hexadecimal as the array subscript to directly obtain the corresponding seven-segment code bytes
6. {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
7. static unsigned char i=0; // (0≤i≤7) Refresh the display in a loop. Since it is a static variable, this assignment is only done once.
8. P2 = 0xff; //Display blanking to prevent the next code value from being displayed on the previous SLED
9. P1 = Seg7Code[ DisBuf[i] ]; //Get the original data from the display buffer, convert it into seven-segment code after looking up the table, and then send it to the display
10. P2 = cathode[ i ]; //Set the corresponding cathode to low and display
11. if( ++i >= 8 ) i=0; //point to the next digital tube and corresponding data
12. }
13. void Timer0IntRoute( void ) interrupt 1
14. {
15. TL0 = -1000; //Since TL0 has only 8 bits, assign the lower 8 bits of (-1000) to TL0
16. TH0 = (-1000)>>8; // Take the high 8 bits of (-1000) and assign them to TH0, re-timing 1ms
17. DisplayBrush();
18. }
19. void Timer0Init( void )
20. { TMOD=(TMOD & 0xf0) | 0x01; // Initialization, timer T0, working mode 1
21. TL0 = -1000; // Timing 1ms
22. TH0 = (-1000)>>8;
23. TR0 = 1; //Allow T0 to start counting
24. ET0 = 1; //Allow T0 to generate an interrupt request when the count overflows
25. }
26. void Display( unsigned char index, unsigned char dataValue ){ DisBuf[ index ] = dataValue; }
27. void main( void )
28. {
29. unsigned char i;
30. for( i=0; i<8; i++ ){ Display(i, 8-i); } //DisBuf[0] is right, DisBuf[7] is left
31. Timer0Init();
32. EA = 1; // Allow CPU to respond to interrupt requests
33. While(1);
34. }
Previous article:51 MCU Programming Section 5: Keyboard Driver
Next article:51MCU PWM
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
- TMS320C66x dual loop and multiple loop optimization summary
- [Top Micro Smart Display Screen Review] 3. Run SciTE Lua script editor to test the screen alarm function
- Material problem of wifi gun
- The processing of instantaneous signals, the signal is -50mV-0V, the time length is 16us, such instantaneous signals need to be extracted and processed...
- Can adding a resistor in parallel to the load effectively prevent voltage fluctuations?
- 【TGF4042 signal generator】+Sweep application in issue 7
- Why does the microcontroller stop working after the DIP switch circuit is powered on?
- Download and receive gifts | The era of artificial intelligence and the Internet of Things is coming, are you ready?
- 【TGF4042 signal generator】+ Basic function mode test
- [Project source code] ARM assembly instructions serial 1