The digital tube of this learning board uses P0 to display the strokes, and P2 to select each word.
//The simplest way to change the display content after a delay
Reference address:MCU program 3, digital tube displays 0-9 self-test
#include
#include
unsigned char data dis_digit;
unsigned char code dis_code[11] =
{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0xFF}; //Common anode digital tube
unsigned char data dis_buf[10];
unsigned char data dis_index;
unsigned char i = 0, j = 0;
void main(void)
{
unsigned char i;
P0 = 0xFF;
P2 = 0xFF;
TMOD = 1;
TH0 = 0xFC;
TL0 = 0x17;
IE = 0x82;
for(i=0;i<=9;i++)
{
dis_buf[i] = dis_code[i];
}
dis_digit = 0xFE;
dis_index = 0;
TR0 = 1;
while(1);
}
void timer0() interrupt 1
//Timer 0 interrupt service routine, used for dynamic scanning of digital tubes
//dis_index--display index, used to identify the offset of the current digital tube and buffer
//dis_gigit--bit selection channel, transmitted to P2 port to select the current digital tube value, such as 0xFE to select the P2.0 port digital tube
//dis_buf--display buffer base address
{
TH0 = 0xFC;
TL0 = 0x17;
P2 = 0xFF; //Turn off all digital tubes first
P0 = dis_buf[dis_index];
P2 = dis_digit;
dis_digit = _crol_(dis_digit, 1); //Shift the bit selection channel to the left, and select the next digital tube at the next interrupt
i++;
if (i==100)
{
j++;
i = 0;
if (j == 5)
{
dis_index++;
if (dis_index == 10)
{
dis_index = 0;
}
i = 0;
j = 0;
}
}
//dis_index &= 0x07; //All 8 digital tubes have been scanned, restart
}
Previous article:51 single chip microcomputer pulse controller
Next article:MCU LED program 2, using timer PWM to realize LED gradual brightness
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Electronic hourglass based on physical model
- EEWORLD University Hall----Live Replay: Melexis High Reliability Programmable Hall Switch
- 2. Onboard RGB light control
- How to self-test the fault of resistor parallel circuit?
- Auxiliary trainer for plank and push-up exercises
- MSP430 sets the main clock source, main clock source and auxiliary clock source
- What are the transmission distances of Zigbee and Bluetooth respectively? Which one has unlimited distance transmission?
- Impedance Matching and the Smith Chart: The Basics
- ATH10 temperature and humidity measurement is inaccurate
- Happy Little New Year! How many days off do you have for the New Year?