/*-----------------------Include header file area-------------------------*/
#include /*-----------------------Function declaration area---------------------------*/ void delay(unsigned int xms); //delay function declaration /*-----------------------Main function area-----------------------------*/ void main() { unsigned char i,j; //define unsigned character type variables i and j (range 0~255) while(1) // Repeat the while loop program { i=0xFF; //assign value 1111 1111 to i P2=i; //Assign the value of i to the P2 port delay(500); //delay 500ms for(j=0;j<8;j++) // loop 8 times { i=i<<1; //Shift the value of i left by 1 bit (discard the high bit and fill the low bit with 0) P2=i; //Assign the value of i to port P2 delay(500); //delay 500ms } } } /*---------------------------------------------------------------- Function name: delay Function: Delay Function parameter: xms is the delay time Return value: None ----------------------------------------------------------------*/ void delay(unsigned int xms) { unsigned int i,j; //define unsigned integer variable i (range 0~65535) for(i=xms;i>0;i--) //Execute xms times, i.e. delay x milliseconds for(j=115;j>0;j--); //Delay 1ms (assign a delay value of 1ms to i, and when the loop body is empty, execute the i-- instruction 115 times for 1ms) }
Previous article:51 single chip microcomputer STC89C52 drives a digital tube to display 0~9, A~F
Next article:51 single chip microcomputer STC89C52 controls the LED marquee to move left (using C51 built-in library _crol_() to implement)
- 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
- STEVAL-IDB0071V1_ by gs001588
- Proteus 8.9 supports STM32F401
- zd test zd test 1
- Help: Why does the pin have voltage output when the PIC microcontroller port is set as input?
- Three important rules about EMC certification
- Micro Python Web Framework: microdot
- EEWORLD University ---- Building Block DAC: System Thinking Method
- Single package six-channel digital isolator and IPM interface reference design for inverter
- [Silicon Labs Development Kit Review] + Building Simplicity Studio Development Environment
- Tiger Wish: Make a wish for 2022, usher in good luck in the new year, and take away the EEWorld New Year gift~