Now, C51 has been widely promoted and applied in the programming of single-chip microcomputers. It is regarded as the mainstream design program of single-chip microcomputers. It can even be said that it is a language that single-chip microcomputer developers must master.
As a tool, the ultimate goal is to achieve functions. Under this premise, we hope that our programs can be easily understood by others, or that we can easily understand other people's programs, so that we can achieve twice the result with half the effort in group cooperation development. When requesting help online, if you can post the program in a standardized way, netizens will find it easier to understand your problem, and you will get help from netizens faster. Otherwise, people will not understand it after reading it for a long time, which will not achieve the expected effect. Therefore, in order to facilitate the exchange of source programs and reduce obstacles in cooperative development, I hope everyone can discuss the programming standards of C51. I think it will be a very meaningful thing to put forward the suggestions that everyone thinks are good, and then make a summary as a standard that everyone agrees on. I will first put forward some of my own ideas to stimulate discussion.
1. Notes
1. Use Chinese;
2. Initial notes:
File (module) annotation content:
company name, copyright, author name, modification time, module function, background introduction, etc. Complex algorithms need to be accompanied by process descriptions;
for example:
/*Module name: LCD module LCD model: HD44780 */
/*Created by: zhaojunjie Date: 2001-06-08 */
/*Version:
Comments at the beginning of a function:
function name, function, input description, return, function description, process handling, global variables, call examples, etc. Complex functions need to include variable usage descriptions;
/************************************************************************
*
* Function name: v_LcdInit
* Function description: LCD initialization
* Function description: Initialization command: 0x3c, 0x08, 0x01, 0x06, 0x10, 0x0c
* Calling function: v_Delaymsec(),v_LcdCmd()
* Global variables:
* Input: None
* Return: None
* Designer: zhao Date: 2001-12-09
* Modifier: zhao Date: 2001-12-09
* Version:
***********************************************************************/
3. Comments in the program:
Modification time and author, notes for easy understanding, etc. The notes should be concise, clear and concise, and self-explanatory sentences should not be annotated.
2. Naming:
The naming must have certain practical significance.
1. Naming of constants: all in uppercase.
2. Variable naming:
add a prefix to the variable name. The prefix reflects the data type of the variable and is in lowercase. The first letter that reflects the meaning of the variable is capitalized, and the others are lowercase.
Variable data types:
unsigned char prefix uc signed char prefix sc
unsigned int prefix ui signed int prefix si
unsigned long prefix ul signed long prefix sl
bit prefix b pointer prefix p
Example: ucReceivData receives data
3. Structure naming:
4. Function naming:
the first letter of the function name is capitalized. If it contains two words, the first letter of each word is capitalized.
Function prototype description includes: references to external functions and internal functions. External references must indicate the function source on the right: module name and file name. For internal functions, just comment on its definition file name;
3. Editing Style
1. Indentation: Indentation is in Tab units, and one Tab is four spaces. Preprocessing statements, global data, function prototypes, titles, additional instructions, function descriptions, labels, etc. are all written in top-aligned order. The "{" and "}" of a statement block are aligned in pairs and aligned with the previous line;
2. Spaces: Data and functions should have appropriate spaces between their types and modifiers and should be aligned as appropriate. Keywords should be left blank in principle, such as
if ( ... ), etc. The space rules for operators are as follows: "->", "[", "]", "++", "--", "~", "!", "+", "-" (for positive and negative signs), "&" (addressing or reference), "*" (for pointers), etc. should not have spaces on both sides (unary operators refer to the side connected to the operand), other operators (including most binary and ternary operators) should have one space on both sides, "(", ")" operators should have one space inside, and when defining a function, they can be aligned with more or no spaces as appropriate, but this is not necessary when implementing a function. The "," operator should only have one space after it, and it can be left blank or with more spaces when alignment is required. Comments added after a statement line should be separated from the statement with appropriate spaces and aligned as much as possible.
3. Alignment: In principle, closely related lines should be aligned, including alignment of types, modifiers, names, parameters, etc. In addition, the length of each line should not exceed the screen too much. If necessary, wrap the line appropriately. Wrap the line at "," or at the operator as much as possible. After wrapping the line, it is best to start with the operator, and the following lines are indented with the first line of the statement, but the statement is still indented with the first line, that is, if the next line is "{", it should be aligned with the first line.
4. Blank lines: Leave two blank lines between each part of the program file structure. If it is not necessary, leave only one blank line. Generally, leave two blank lines between each function implementation.
5. Modifications: After the version is sealed, the old statements must be closed with a , and cannot be deleted or modified by yourself, and must be recorded in the modification history of the file and function.
6. Formal parameters: When defining a function, the formal parameters are described directly in brackets after the function name without further explanation.
Previous article:Application of C language in single chip microcomputer development
Next article:C51 Questions and Answers
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Design principle of pressure level gauge.
- Share some methods for beginners to learn 430 microcontroller
- In a circuit powered by a 10V DC voltage source, a 4uF 6uF 1 ohm resistor is connected in series. What is the voltage of the two capacitors when the steady state is reached?
- Getting Started with TI CC1310 sub1G SDK Development
- Questions about phase shifting
- Free sharing of senior hardware engineer's video explanation---ADC analog-to-digital converter device design selection guide
- Explanation and correction of MSP430 MCU __delay_cycles precise delay
- The optocoupler is broken, I can't figure out the reason, please give me some advice
- Some information on Hall sensor applications
- Measuring the reluctance problem