The circuit is very simple. The 8-bit running light is connected to the P1 port of the microcontroller. The source code is as follows:
//================================================ =============
//Program name: LLL22_4.C
//Program function: Control the flow light to move left and right
//================================================ ==============
#include//header file
L_M(); //Flowing light left shift control program
R_M(); //Flowing light right shift control program
//================================================ ===============
main() //Main function
{
while(1) // infinite loop
{
L_M(); //Call left shift program
R_M(); //Call right shift program
}
}
//=======Left shift control program================================================
L_M() //Left shift main function
{
unsigned char i,temp,a,b; //declare unsigned character type variables A,TEMP I,B
unsigned int s; //Declare an unsigned integer variable S
temp=0xfe; //left shift initial value
P1=temp; //P1 outputs signal to light up the LED
for( s=0;s<30000;s++); //delay program
for (i=1;i<8;i++) //The number of digits the LED moves
{
a=temp<
Reference address:51 single-chip microcomputer flow light left and right control program
b=temp>>(8-i); //data right shift (8-I) bits
P1=a|b ; //Logical OR operation, and output to P1 port
for(s=0;s<30000;s++); //delay program
}
}
//================================================ ================
R_M()
{
unsigned char i,temp,a,b; //declare unsigned character type variables A,TEMP I,B
unsigned int s; //Declare an unsigned integer variable S
temp=0x7f; //left shift initial value
P1=temp; //P1 outputs signal to light up the LED
for(s=0;s<30000;s++); //delay program
for(i=1;i<8;i++) //The number of digits the LED moves
{ //Shift the LED left by 1 position
a=temp>>i;
b=temp<<(8-i); //data right shift (8-I) bits
P1=a|b; //Logical OR operation, and output to P1 port
for(s=0;s<30000;s++); //delay program
}
}
//================================================ =======================
Previous article:DS1302 clock assembly program digital tube display time
Next article:51 single chip microcomputer controls the forward and reverse rotation of the DC motor
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
- Samsung Suzhou factory announced major layoffs!
- Gaoyun FPGA reports the error "suitable range is from 400MHz to 1200MHz"
- Simple summary of Android Bluetooth pairing communication, app layer implementation of Bluetooth silent pairing, ClsUtils class
- The problem of self-reduction
- Power supply decoupling capacitors
- How to use DFT App for hardware accelerated simulation design
- GD32E23X Standard Library and GD32E230 Standard Library Manual
- CC3200 Kit OURS-SDK-WFB_Explore - by tinnu
- Chip Manufacturing 3-Semiconductor Slicing
- RISC-V IDE MRS Usage Notes (IV): Link-time Optimization