1. Do not define too many variables. The lower 128 bits are the storage area for user-defined variables (by default). You can also put variables in the upper 128 bits, but it is easy to make mistakes. Try to put as few as possible, or better not put them at all. You can view the storage of memory variables through M51. It is best not to exceed 110 bytes, otherwise the program cannot run or errors will occur.
2. If a variable is used in multiple places, it can be defined as a global variable. For example, loop variables i and j, try to reduce parameter passing.
3. Static variables are best placed in the program storage area and defined with code.
4. Variables should be defined as unsigned numbers. Variables that only occupy one bit, such as flags, should be defined as bits.
5. Subroutines should be declared in advance after the main() main program, and those placed in front do not need to be declared.
6. If variables and subroutines are defined but not used, the system will give a warning.
7. Although local variables and global variables have different names, they may be changed by global variables during runtime.
8. After the program is compiled, it is possible to generate very large files. For example, the original 5k becomes 10k after compilation. This is caused by the arbitrary allocation of program space during C assembly. You can first block part of the program and compile it, then remove the block and compile it again, you can restore it, or copy it part by part to another file and compile it.
9. If a timer is used to generate a pulse signal, when you want to remove the pulse signal, you should first turn off the timer, and then set the level to high or low as required.
10. The "watchdog" function can be implemented using software. For example: a program takes 50ms to run a cycle, then the timer can be set to 100ms. When it exceeds 100ms, the program will reset, and the timer will be reloaded or the timer parameters will be reset at the bottom of the program cycle.
Previous article:How to easily transform 51 MCU to ARM design?
Next article:Comparison of AVR, STC and 51 MCU
Recommended ReadingLatest update time:2024-11-23 02:39
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
- 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
- Identification of color ring resistors
- Four-quadrant stepper motor control simulation with interpolation calculation and single-chip microcomputer source program
- Very useful! The voltage, current and temperature safety zones of 13 types of components in switching power supplies!
- It's time to change! Awesome change, the latest design to replace RS-485 optocoupler isolation
- 7V boost to 12V circuit
- EEWORLD University ---- 3D TOF occupancy detection: body tracking and counting
- Exploring the secrets of mobile phone power management technology
- [LSM6DSOX finite state machine routine learning four] --4D detection (FourD position recognition)
- [Silicon Labs Development Kit Review] + Temperature and Humidity Sensor Si7021
- Smart socket