Manual display
#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 : Two common cathode digital tube dynamic display ====================================*/ void display(uchar num1, uchar num2) { /*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); } void main()//main function itself will loop { while(1) { display(0, 0); //Nigital tube display function } } illustrate: Due to the parameter passing, to display a total of 11 numbers from 00 to 10, you only need to call Custom function void display(uchar num1, uchar num2) Pass in: display(0,1); display(0,2); display(0,3); display(0,4); display(0,5); display(0,6); display(0,7); display(0,8); display(0,9); display(1,0); So the other codes above are no longer copied. display automatically #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 uchar count = 0; // Variables that control the display of the digital tube uchar i = 0; // Variable that controls the number of loops //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 : Two common cathode digital tube dynamic display ====================================*/ void display(uchar num1, uchar num2) { /*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); } /*==================================== Variable count: Responsible for controlling which two digital tubes are lit. For example, if count is 1, then the 01 digital tube is lit. Description : Since two digital tubes are lit at the same time, the continuous circulation of the two digital tubes is required to achieve the simultaneous lighting of the two digital tubes. So here we encapsulate the code that displays the digital tube on the microcontroller and let us call it. ====================================*/ void singlechip_show_num(uchar count){ switch(count){ // Precisely manage the digital tube values through switch case statements case 0 : display(0, 0); break; case 1: display(0, 1); break; case 2: display(0, 2); break; case 3: display(0, 3); break; case 4: display(0, 4); break; case 5: display(0, 5); break; case 6: display(0, 6); break; case 7: display(0, 7); break; case 8: display(0, 8); break; case 9: display(0, 9); break; case 10: display(1, 0); break; } } void main()//main function itself will loop { while(1) { for (i = 0; i < 200; i++){ // Cycle the lit digital tube 200 times to ensure that the digital tubes visible to the human eye are displayed at the same time. singlechip_show_num(count); // Call the digital tube display function } count++; //Each loop ends 200 times, the count variable itself +1, and the microcontroller displays the value after +1 if(count == 11){ // When the count variable equals 11, we re-initialize the variable to 0 and restart the counting cycle from 0 count = 0; } } } The effect shows:
Previous article:STC89C52 microcontroller uses timer to flash LED light
Next article:STC89C52 microcontroller independent keyboard
- 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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- MSP430G2553 pinout for easy use
- Recruiting a product development manager, based in Shenzhen
- What is the relationship between MOS power dissipation (maximum value) and load power?
- Orthogonal modulation and demodulation questions
- [NXP Rapid IoT Review] + NXP Rapid IoT Prototyping Kit Data Collection
- Special considerations for HUADA MCU design
- [NXP Rapid IoT Review] + Unboxing and Getting to Know the Kit
- Advantages of WiFi6 compared with other WiFi
- KiCad (5.0.2) calculator tool
- Why does the temperature reading of MAX6675 always have an error of about 2 degrees?