Of course, when using a general single-chip microcomputer for programming, encapsulating the program segments that achieve the same purpose and performing modular programming will also be very helpful for program maintenance and debugging.
1. When using C language for programming, you should develop good programming writing habits.
The general format at the beginning of the program is:
/**********************
File name: File name
Author:
Version: Version number
Description: Functional description
Data: Date
*************************/
2、{}
Press the Tab key so that the program hierarchy is clearer.
3. Modular programming
Encapsulate the program segment that completes a specific function, such as delay(WOED n), eeprom();, etc.
Specific steps are as follows:
1. Create a header file
Click "New" twice in the KEIL software to create two new documents. Save them as a .C file (source file) and a .H file (header file). The .C and .H files should have the same name, and the name should be meaningful, and it is best to reflect the function of the file. For example, create a delay program, delay.c; delay.h.
2. Anti-duplicate inclusion processing
Add the following code to the .H file:
#ifndef xxx 如 #ifndef __DELAY_H__
#define xxx 如 #define __DELAY_H__
……
#endif
3. Code encapsulation
Encapsulate the code that needs to be modularized into functions or macro definitions.
Functions must be declared in the header file.
The function body is placed in the .C file.
Macro definitions that need to be called externally are placed in the .H header file.
Try to use as few or no global variables as possible. Global declarations must be placed in .C files. When you need to call external global variables, you need to re-declare them using extern in the .H file.
4. Use source files
In the KEIL software project, add the .C file to be called. If the .C source file calls the macro definition or function in the .H file, you must add code to the .C source file to include the .H file.
5. The functions, macro definitions, and global variables in the included header files can be called freely in the .C files.
The details will be sorted out when time permits.
Previous article:MCU dynamic digital tube display hello assembly program
Next article:Detailed explanation of MCS-51 MCU assembly instructions
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Playing with Zynq Serial 45——[ex64] Image Laplace Sharpening Processing of MT9V034 Camera
- New employee: I am the most idle person in the company, so my boss assigned me to write the bootloader
- I feel like I can't stay in this stupid company any longer.
- TI High Power Density Solution Analysis!
- Can the CH246 & CH241 wireless charging kit be used like this?
- Popular Science Sharing - Detailed Explanation of the Working Principles of Starlink Satellites (Episode 1)
- Thank you for your strong faith
- MCU SPI communication interface
- Overview of MCU bus, three-bus structure of MCU
- Comparison summary of MSP430 FR2xx series MCU BSL and MSP432 P series MCU BSL