1、
The program implements the function: Let 8 LEDs light up in a row 1—》...——》8 1《——...《——8 The arrows represent the direction of the LED flow, first from 1-8 and then from 8 to 1. The program has been tested and runs normally // If you use this code to test, pay attention to which port your LED is connected to the microcontroller. This code uses port P2
#include
#define uint unsigned int
#define uchar unsigned char
fly a,b;
uchar code led_array[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f
}; //LED display code array, from 0xfe to 0x7f, from the first LED tube to the eighth LED tube, one at a time, the format is 0fff ffff\f0ff ffff\ff0f ffff...ffff fff0\ LED starts to light up from 1, and when it reaches the eighth LED, it starts to light up in the reverse direction ffff fff0\ffff ff0f\ffff f0ff...0fff ffff (Note: 0 represents light; 1 represents no light) I don't know if you understand what I mean....
void delay(uint x)
{
uint z,y;
for(z=x;z>0;z--)
for(y=110;y>0;y--);
}//Delay function
void sumup_ini()
{
P2=0xfe;//
}//Total initialization function, I like to write programs in modular form, but this module is too small... cough cough cough!!!
void main()
{
sumup_ini(); //Call the total initialization function
while(1) This goes without saying!
{
for(a=0;a<8;a++)
{
P2=led_array[a];
if(P2!=led_array[7]) //Here we use if to determine whether the last LED is on. If it is the last one, the delay function will not be executed. Otherwise, the following delay function will be executed every time the LED moves one position.
/*(Here is the explanation of why we need to judge whether the last LED is lit. If the delay is executed after the last LED is lit, it will be the same as the initial value of the reverse flow function. led_array[7] is the first LED that is lit in the reverse flow and the last LED that is lit in the reverse flow. So if we don’t use if to judge, it is equivalent to delaying the time of other LEDs in led_array[7] by 2 times... In order to make the time of each LED being lit equal, I use if to judge the following)*/
delay(500);
} //LED forward flow lights up
for(b=7;b>0;b--)
{
P2=led_array[b];
delay(500);
} //LED direction flow light
}
}
Previous article:4x4 matrix keyboard scanner
Next article:MCU 4*4 matrix keyboard
Recommended ReadingLatest update time:2024-11-16 14:34
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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
- Can you please help me analyze the principle of this circuit? Thank you.
- EEWORLD University Hall----Live Replay: ON Semiconductor's advanced packaging and driver technologies help silicon carbide energy applications
- EEWORLD University Hall----Robotics Visual Control Matlab Simulation
- MSP430FR2111 cannot send data
- EEWORLD University Hall----Intelligent Building Wireless Solutions
- [ATmega4809 Curiosity Nano Review] Serial port key control light (IoT Led Part 1)
- Can STM32G431 perform "bit-band operation"?
- Big news - TI launches the smallest data converter with high integration and high performance!
- Timer
- Teensy 4.0 Development Board