1. Static display of a single digital tube
/*--------------------------
Function: Static display of a digital tube
Author: Zhang Kaizhou
Date: 2019-5-16 21:18:17
--------------------------*/
#include sbit duan_address = P2^6; // Define segment address as a bit addressable variable sbit wei_address = P2^7; // Define the bit address as a bit addressing type variable void main() { wei_address = 1; // Open the bit latch P0 = 0xfe; // Output the position of the digital tube wei_address = 0; // Turn off the bit latch duan_address = 1; // Open the segment latch P0 = 0x7d; // Output the segment code of the common cathode digital tube (6) duan_address = 0; // Close the segment latch while(1); } 2. Dynamic cycle display of digital tube /*----------------------------------- Function: Cycle display of 16 characters from 0 to F on the digital tube Author: Zhang Kaizhou Date: 2019-5-16 21:41:50 -----------------------------------*/ #include #define uchar unsigned char #define uint unsigned int sbit wei_address = P2^7; // Define a bit-addressable variable wei_address sbit duan_address = P2^6; // define bit-addressable variable daun_address uchar num; // define unsigned character variable num uchar code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; // Define an unsigned character array table[] to store the segment code of the common cathode digital tube (0~F characters), which is stored in the ROM or Flash inside the microcontroller void delay(uint xms); void main() { wei_address = 1; // open latch P0 = 0x00; // Select the digital tube to be displayed wei_address = 0; // Close the latch while(1) { for(num = 0; num < 16; num++) // Cycle through the digital tube to display characters 0 to F { duan_address = 1; // Open the segment latch of the digital tube P0 = table[num]; // Output segment code duan_address = 0; // Close segment latch delay(1000); // Delay 1000ms = 1s } } } void delay(uint xms) { uint i, j; for(i = xms; i > 0; i--) for(j = 110; j > 0; j--); } 3. Dynamic scanning display of multiple digital tubes /*----------------------------------- Function: Dynamically display character information on 4 digital tubes Author: Zhang Kaizhou Date: 2019-5-16 21:41:50 -----------------------------------*/ #include #define uchar unsigned char #define uint unsigned int sbit wei_address = P2^7; // Define a bit-addressable variable wei_address sbit duan_address = P2^6; // define bit-addressable variable daun_address uchar num; // define unsigned character variable num uchar code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; // Define an unsigned character array table[] and store it in the ROM or Flash inside the microcontroller void delay(uint xms); void main() { while(1) { // Display 0 duan_address = 1; P0 = table[0]; duan_address = 0; wei_address = 1; P0 = 0xfe; wei_address = 0; delay(5); // Display 1 duan_address = 1; P0 = table[1]; duan_address = 0; P0 = 0xff; // erase wei_address = 1; P0 = 0xfd; wei_address = 0; delay(5); // Display 2 duan_address = 1; P0 = table[2]; duan_address = 0; P0 = 0xff; // erase wei_address = 1; P0 = 0xfb; wei_address = 0; delay(5); // Display 3 duan_address = 1; P0 = table[3]; duan_address = 0; P0 = 0xff; // erase wei_address = 1; P0 = 0xf7; wei_address = 0; delay(5); } } void delay(uint xms) { uint i, j; for(i = xms; i > 0; i--) for(j = 110; j > 0; j--); }
Previous article:51 MCU internal timer usage
Next article:LCD1602 dynamic display
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- 5 days left to register | Full schedule of the annual AIoT Developer Conference! 19 technical lectures full of practical information!
- STEVAL-IDB010V1 BlueNRG-LP evaluation board data
- Revealing the secret! How can 100 MHz power decoupling hold Gbps high-speed signals?
- I don't know how many days I have been learning HFSS
- [STM32F769Discovery development board trial] USB-HS HID simple transmission and reception evaluation
- There is a problem with testing multimedia
- Use chips that support the BLE 4.2 specification to implement application system design
- TMS320F2812 advice
- EEWORLD University Hall----Parallel Computing
- CPU temperature exceeds the limit