In single-chip microcomputer application systems, especially for large and complex systems, it is not feasible to put them in one file because there are so many sensors and processing modules. At this time, modular processing is required.
Make each module into a .c file and a .h file. Functions in a .c file will only call each other, and will not call functions in other files. Try to minimize cross-calling of functions in different files. Here are a few issues to pay attention to:
(1) Measures to prevent duplicate inclusion of module header files
At the beginning of the .h file in each module, to prevent repeated inclusion, use the following code:
#ifndefine xxx //If xxx is not defined, compile the following statement
#define xxx //Then define xxx so that it is included only once. The next time you check, you will find that it has been defined.
……. // If xxx is included, it will not be included again
#endif
(2) Code encapsulation
1. The function is declared in the header file and the function body is placed in the .c file;
2. Macro definitions that are only called in this .c file should be placed in the .c file, and macro definitions that need to be called by other files should be placed in the header file;
3. Use global variables as little as possible. When you must use them, put them in the .c file for your own use. When the global variable needs to be called externally, declare it with extern in the .h file.
Previous article:Features and Introduction of HuaDa Electronics MCU-CIU32F011x3, CIU32F031x5
Next article:How does a microcontroller communicate with a computer? Electronic engineers must know
Recommended ReadingLatest update time:2024-11-23 11:32
- Popular Resources
- Popular amplifiers
- Analysis and Implementation of MAC Protocol for Wireless Sensor Networks (by Yang Zhijun, Xie Xianjie, and Ding Hongwei)
- Introduction to Internet of Things Engineering 2nd Edition (Gongyi Wu)
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Modern Motor Control Technology (Wang Chengyuan, Xia Jiakuan, Sun Yibiao)
- 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
- [Ateli Development Board AT32F421 Review] 7. Kuga registers jointly light up OLED
- Design and FPGA implementation of digital on-screen display control core.pdf
- ARM Development Process
- The difference between NOR flash and NAND flash
- Working Principle of Current Mode PWM Controller
- EL817C Optocoupler Transmission Ratio Problem
- Keysight Technologies N9020A 3.6G spectrum analyzer special sale: 8500/unit
- STM32+photosensitive sensor+serial port receiving light intensity source program is successfully produced
- Digital TV boom enters the automotive market
- 【GD32F350 LogicKids】Flash jump