Circuit connection: P1 port is connected to the segment select and chip select of the eight-bit digital tube through two 74HC573. The segment select and bit select are controlled by P3.4 and P3.5. The low level latch
#include#define DIGI_PORT P1 // Macro definition of digital tube port. If the port changes, just modify this sentence #define DIGI_NUM 8 // Macro definition of the number of digital tubes sbit DULA = P3^4; sbit WELA = P3^5; unsigned char digiBuf[DIGI_NUM]; //Digital tube buffer unsigned char code DigiTable[] = { 0x3F,/*0*/ 0x06,/*1*/ 0x5B,/*2*/ 0x4F,/*3*/ 0x66,/*4*/ 0x6D,/*5*/ 0x7D,/*6*/ 0x07,/*7*/ 0x7F,/*8*/ 0x6F,/*9*/ 0x00,/* */ }; /* Initialize timer 0, mode 1, 11.0592MHz crystal oscillator, interrupt every 5ms, If there are only 4 digital tubes, 10ms is enough, and the interval length can be adjusted according to the actual situation. While ensuring no flickering, increase the interval as much as possible to reduce CPU resource consumption */ void initDigi() { TMOD = 0x01; TH0 = 0xEE; TL0 = 0x00; EA = 1; ET0 = 1; TR0 = 1; } void main() { digiBuf[0] = 10; // If it is 10, this bit will not be displayed digiBuf[1] = 1; digiBuf[2] = 2; digiBuf[3] = 3; digiBuf[4] = 4; digiBuf[5] = 5; digiBuf[6] = 6; digiBuf[7] = 7; initDigi(); while(1); } // Timer 0 function runs once every certain period of time void displayTimer0() interrupt 1 { static unsigned char digiPos = 0; // The digital tube that needs to be displayed currently. Use static local variables or global variables here. Do not use default local variables. TH0 = 0xEE; TL0 = 0x00; // Turn off all digital tubes by bit selection, otherwise ghosting may occur (after the segment selection is changed and before the bit selection is changed, the digital tubes that were last turned on by bit selection will display wrong information) DIGI_PORT = 0xFF; //If this sentence is swapped with the next sentence, it may cause ghosting. For details, see http://blog.csdn.net/jzj1993/article/details/8563337 HOT = 1; TEMPERATURE = 0; // Perform segment selection here (all digital tubes are turned off at this time, and no error message will be displayed) DIGI_PORT = DigiTable[digiBuf[digiPos]]; GAME = 1; GAME = 0; // Here, the position is selected according to digiPos switch(digiPos) { case 0: DIGI_PORT = ~(1 << 0); break; // Turn on the 0th digital tube case 1: DIGI_PORT = ~(1 << 1); break; // Turn on the first digital tube case 2: DIGI_PORT = ~(1 << 2); break; // Turn on the second digital tube case 3: DIGI_PORT = ~(1 << 3); break; // Turn on the third digital tube case 4: DIGI_PORT = ~(1 << 4); break; // Turn on the 4th digital tube case 5: DIGI_PORT = ~(1 << 5); break; // Turn on the 5th digital tube case 6: DIGI_PORT = ~(1 << 6); break; // Turn on the 6th digital tube case 7: DIGI_PORT = ~(1 << 7); break; // Turn on the 7th digital tube } HOT = 1; TEMPERATURE = 0; // Change the digiPos value to prepare for the next entry into this function digiPos++; if(digiPos == DIGI_NUM) digiPos = 0; }
Previous article:Basic knowledge of 51 MCU program development
Next article:Basic Analysis of 51 Single Chip Microcomputer (Based on C Language)
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- How much do you know about flash memory technology?
- Copper Radiator VS Aluminum Radiator
- The founder of the Phicomm router that was bought for 0 yuan was sentenced to life imprisonment
- A small talk: Do you like reading books? Do you read e-books, buy books, or go to physical stores?
- IC Layout (2)
- Why does the CAN message fail to send?
- How to understand the equivalent of capacitors passing AC
- Flower watering system based on AVR16 single chip microcomputer
- Several commonly used code comparison tools
- Matrix keyboard code, proteus simulation is fine, but there is a problem when downloading to HC6800-ES V2.0