#include #define LED P0 void delay(); //delay for one second void main() //Bitwise operation to light up the small light { unsigned int i; while(1) { for(i = 0;i<8;i++) { LED = ~(0X01< delay(); } } } void delay() //delay for one second { unsigned int i,j; for(i = 0;i<83;i++) { for(j = 0;j<1000;j++) { ; } } } Since the blogger is at home during the winter vacation and does not have a 51 single-chip microcomputer, I used Proteus to build a simple circuit, wrote the file with keil5 to generate a .hex file, and then added it to Proteus to run. The specific operations are as follows: Then check the following options: Then save the written code and finally open the Proteus software. Build the circuit as follows: Then insert the code to combine with the circuit: Select the .hex file to confirm, then run in the lower left corner: The operation is as follows, blue means the small light is running normally: We can see the small lights cycle from the first light to the eighth light. Careful friends can see that the delay time set by our delay() function is one second. Why is it one second? The control here is quite clever. Two for() loop statements are used. The outer loop is executed 83 times and the inner loop is executed 1000 times, which means that the total execution is 83 * 1000 times. In C language, the number of seconds to execute a statement can be observed by setting breakpoints before and after. In order to deeply understand why the program can reach 1 second after executing 83 * 1000 times, we set a breakpoint before and after this statement respectively, and roughly judge the program's pointing time by observing the time difference between the two endpoints:
Previous article:51 MCU Learning Notes——3. Several different ways of lighting LED (array form) and key detection, delay debounce
Next article:Learn MCU interrupts in 1 day - basic knowledge
Recommended ReadingLatest update time:2024-11-23 11:07
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- I really want to give up GoLang
- Digital tube driver advice
- [TI recommended course] #Boost and buck-boost DCDC converters help wireless charging design#
- How does the MCU in a drone work?
- MSP430FR6972 watchdog cannot restart the program
- MTS3300EV
- About the cyclone soc network port printing link donw linkup problem
- China Mobile and China Unicom have reached a handshake agreement that mobile phone charges will be transferred without distinction within or outside the network
- What kind of AC socket is most suitable for low-power devices
- How to connect the three wires of GND, VCC and Vout to BNC or XLR port?