Modular Programming

Publisher:DazzlingSmileLatest update time:2024-08-14 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Reference address:Modular Programming

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

SmartSite launches new high-end super starlight-level large-area 8MP image sensor SC880SL
SmartSite launches new high-end super starlight-level large-area 8MP image sensor SC880SL March 17, 2023, Shanghai, China - Smartway (Shanghai) Electronic Technology Co., Ltd. officially launched the new Star Light (SL) Series super starlight series large-area 8MP image sensor for high-end intelligent security appli
[sensor]
SmartSite launches new high-end super starlight-level large-area 8MP image sensor SC880SL
Thinking about the low-cost development of sensors in the era of the Internet of Things
 The Internet of Things is one of the development trends of the global information industry and is also a key development direction of my country's "12th Five-Year Plan". At present, the country is vigorously developing the Internet of Things industry. From 2010 to 2015, it is the introduction period of the Interne
[sensor]
Thinking about the low-cost development of sensors in the era of the Internet of Things
Working principle of ion smoke sensor
This is a fire alarm When smoke enters the outer ionization chamber, some positive and negative ions are adsorbed in the smoke and burn to generate particles (the particles generated by combustion are about 1000 times larger than ions), which greatly reduces their movement speed in the electric field, and p
[Industrial Control]
Working principle of ion smoke sensor
Design and application of virtual capacitive sensor detection system
Introduction    Capacitive sensors have the advantages of simple structure, high sensitivity, fast dynamic response, and easy non-contact measurement. Although they are easily affected by external interference and parasitic capacitance, with the rapid development of electronic technology and the emergence of drive c
[Test Measurement]
Design and application of virtual capacitive sensor detection system
Leuze Easy Learning Class Sharing - Principle and Application of Ultrasonic Sensors
Optical Sensor is a device that converts light signals into electrical signals. It plays a vital role in automated production. With its excellent performance and wide applicability, Leuze optical sensors have become experts in this field. Its products are widely used in logistics automation, packaging indust
[robot]
WB series power isolation sensor/transmitter selection
    Abstract: Based on an overview of the basic characteristics and functions of power isolation sensors/transmitters, the main uses, classification characteristics and selection methods of WB series power isolation sensors are comprehensively introduced, and the WB series power isolation sensors/transmitters are giv
[Test Measurement]
Scientists invent new materials that can emit multiple colors of light and can be used for sensors/car lights, etc.
Physicists at the University of Alberta in Canada, in collaboration with the Technical University of Munich, have invented a molecular dye that can emit more colors of light than any other molecule currently available. "This material could be used in a variety of applications, including sensors, bioimaging and o
[Automotive Electronics]
Scientists invent new materials that can emit multiple colors of light and can be used for sensors/car lights, etc.
Introduction to Hall Current Sensor
With the development of automobile and internal combustion engine vehicle technology, automobile batteries and current management have gradually become the focus of future automobile technology. Although the open-loop Hall current sensor has slightly lower accuracy and response speed, it has more advantages in cost
[Analog Electronics]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号