I made a simple running light in my spare time. The design idea is to display the LED lights from 0 to 7 one by one, and then from 7 to 0 one by one. If an external interrupt occurs (i.e. a button is pressed), all 8 LED lights will light up, and then the running light state will be restored.
#include #include #define uchar unsigned char #define uint unsigned int sbit K=P3^2; //Start button, external interrupt uchar led; void delay(uint x) { while(x--); } void XX()//interrupt setting { EA=1; EX0=1; } void DD() { uint i=0; //define i=0 for the following call led=0xfe; //1111 1110 delay(30000); while(1) { for(i=0;i<7;i++) { led=_crol_(led,1); //1111 1101 (A,B), A is the value of left shift, B is the number of bits of left shift P1=led; delay(30000); } for(i=0;i<7;i++) { led = _cror_ (led, 1); // 0111 1111 P1=led; delay(30000); } } } void main() { XX(); DD(); } void XX1() interrupt 0 { delay(1000); //anti-shake if(K==0) { P1 = 0X00; delay(30000); } }
Previous article:The PWM wave of the single-chip mechanical arm controls multiple servos according to regular movements
Next article:51 single chip Hall bicycle meter speedometer odometer
Recommended ReadingLatest update time:2024-11-16 23:39
- Popular Resources
- Popular amplifiers
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
- Does TMS320C6748 support TFTP instance in stareware?
- Asynchronous Serial Transceiver Design Report.docx
- Design of robotic arm gesture tracking and voice control system
- A new trend in home appliances, PI opens up your new life in home appliances! Download product information and answer questions to win prizes!
- Voltage acquisition circuit
- Problems with IO pin configuration when STM32 is low power
- Lei Jun: Young people should not make suggestions on strategy and business within six months of joining the company, as many of their ideas are unreliable!
- The baby was born--received a special care from the forum
- Low-level error "while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)" infinite loop
- [Silicon Labs BG22-EK4108A Bluetooth Development Review] Part 1: Unboxing