/*51 MCU controlled LED flashing pattern program, pre-store various flashing combinations of LED lights in the table, then use the table lookup to read the data in the table and output it to the P2 port. This method is often used to control neon lights. The original source of this program: 51Hei MCU http://www.51hei.com , the source code is as follows, if you have any questions, please correct me*/
#include
void main(void)
{const unsigned char design[32]={0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F, 0x7F,
0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF, 0xFF,
0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x0,
0xE7,0xDB,0xBD,0x7E,0xFF}; //Define pattern data unsigned int a; //Define variable unsigned char b
for loop ;
//Due to limited memory, pay attention to the use of variable types in C51 programming
do{ //do while type loop
for (b=0; b<32; b++)
{for(a=0; a<30000; a++); //Delay for a period of time
P2 = design; //Read the defined pattern data and write the pattern data to port P2
}
} while(1);
}
void main() //Main function
{ unsigned char OutData=0xfe; //Define output data and initial value
for(;;) //Infinite loop
{
P2=OutData; //Output OutData to port P2 to turn on an LED in port P2
OutData=_crol_(OutData,1); //Shift OutData left circularly to shift the on LED one position to the left
mDelay(100); //Call the delay function and delay for 100 milliseconds
}}
Reference address:Single chip microcomputer controls the flashing of LED lights
#include
void main(void)
{const unsigned char design[32]={0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F, 0x7F,
0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF, 0xFF,
0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x0,
0xE7,0xDB,0xBD,0x7E,0xFF}; //Define pattern data unsigned int a; //Define variable unsigned char b
for loop ;
//Due to limited memory, pay attention to the use of variable types in C51 programming
do{ //do while type loop
for (b=0; b<32; b++)
{for(a=0; a<30000; a++); //Delay for a period of time
P2 = design; //Read the defined pattern data and write the pattern data to port P2
}
} while(1);
}
void main() //Main function
{ unsigned char OutData=0xfe; //Define output data and initial value
for(;;) //Infinite loop
{
P2=OutData; //Output OutData to port P2 to turn on an LED in port P2
OutData=_crol_(OutData,1); //Shift OutData left circularly to shift the on LED one position to the left
mDelay(100); //Call the delay function and delay for 100 milliseconds
}}
Previous article:Program for single-chip microcomputer to control LED lighting with a single button
Next article:51 MCU timer 0 interrupt service routine
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
- What is the difference between edge triggering (rising edge, falling edge) and level triggering (high level and low level) in digital circuits?
- Does the boost topology circuit limit the duty cycle?
- Op amp differential amplification problem
- FAQ_How to fill in the BQB certification application form
- [2022 Digi-Key Innovation Design Competition] Material Unboxing Raspberry Pi 400
- HC6800 EM3 V2.0 CD-ROM
- Share the temperature and humidity monitoring of LoRa communication technology
- [TI star product limited time purchase] + AWR6843 purchase experience and unboxing
- EEWORLD University ---- VLSI Testing
- 【STEVAL-MKI109V3+LSM6DSOX】Build a test environment from scratch