当前位置:网站首页>Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
2022-04-23 14:42:00 【u010755676】
SO Technology sharing 31
Don't panic when you are confused at first , The sunrise fog dispersed and the road was bright .
This article introduces the definition of 、 To write 、 Save and quote content , Including general format requirements 、 Routine, etc .
What is a header file ?
Header file in C Language is generally necessary in program development , Generally in C The header file must be referenced at the beginning of the program .
Header file as a function containing functions 、 Carrier file for data interface declaration , Mainly used to save the declaration of the program , The definition file is used to save the implementation of the program .
Why use header files ?
If there is no header file , Then the definition is only in C In file , There are several disadvantages :
-> Not easy to read . Put the definition and function code together , Poor readability ;
-> Repeated labor , Increase the number of programs . In all C In file , As long as you use it, you have to redefine , There will be more duplicate code, etc .
For project development, customize , can Q-Q: 2531 26 3726.
What are the general format requirements for writing header files ?

Many things have formats , Do it according to the format. Generally, there will be no error . chart 1 The general structure defined for the header file .
At the beginning #ifndef And the last #endif You need to be in pairs , It means that if a file is not defined , Then perform some operations . stay #ifndef and #endif You can write the code defined by the header file , If other header files are loaded 、 Pin definition 、 Subroutine predefined, etc .
The following table shows the diagram 1 Explanation of some codes in .
surface 1 chart 1 Explain the main points of
| #ifndef __XXX_H__ … #endif |
If there is no definition XXX.H, Then do something . If and endif Must be used in pairs . |
| #define __ XXX _H__ |
Definition XXX.H |
| #include <xxx.h> |
Load the relevant system header file xxx.h |
| #include “yyy.h” |
Load the relevant custom header file yyy.h |
| sbit x=p; |
System bit definition . Generally used to define pins , use x Instead of pins p. |
| #define X Y |
Symbolic variable definition ,X It means Y value .Y Generally, it is a specific value .X and Y There's a space between |
| void XX(); |
Subroutines are predefined . After loading this header file in other programs , Can call XX Subroutines . Predefined in the corresponding C Specific subroutine code has to be written in the document . |
An example of header file writing

There's an example , There will be a more vivid understanding . chart 2 An example defined for a header file , The name bit of the header file relaycontrol.h, This header file contains loading other header files 、 Pin definition 、 Symbolic variable definition 、 Subroutine predefinition, etc .
Save method of header file
Save header files generally have 2 Methods :
(1)、 stay keil Kept in H file : For example , If be in, keil New in H file , After writing the header code , Click the save button , Name it and save it on the computer hard disk ( With the reference to it C The files are in the same folder ) It's OK , The header file saved in this example is relaycontrol.h.
(2)、 Create a new one in your computer TXT file , Change the extension to .h: On the computer hard disk ( With the reference to it C The files are in the same folder ) Create a new one in txt file , Write header file code , preservation , And change the extension to .h. In this case, this txt Change the file name and extension to relaycontrol.h.
How the C Reference header file in program ?

stay C In the program , You need to reference the header before you can use it , Generally, the reference header file is placed at the beginning of the program .
stay C The method of referencing header files in files is very simple , Is to use... In the program “#include” Command to load the corresponding header file .
After reference , In this C The content defined in the header file can be used in the file , As defined by pin 、 Symbolic variables and subroutines .
Whether you need help ?
Provide single chip microcomputer 、PLC、 Circuit board 、 controller / box 、 Instruments and Apparatuses 、 Electromechanical equipment or system 、 automation 、 Industrial control 、 Sensing 、 Data collection 、 Automatic control system 、 Control system , Software 、APP Development, design, customization . If necessary , can Q:2531 26 3726.
At the end of this section , Wonderful to be continued .
版权声明
本文为[u010755676]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231427103405.html
边栏推荐
- qt之.pro文件详解
- MQ-2和DS18B20的火灾温度-烟雾报警系统设计,51单片机,附仿真、C代码、原理图和PCB等
- Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
- 1 - first knowledge of go language
- Logical volume creation and expansion
- Select receives both normal data and out of band data
- Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
- 科技的成就(二十一)
- UML项目实例——抖音的UML图描述
- Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
猜你喜欢

你還不知道責任鏈模式的使用場景嗎?

Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data

1N5408-ASEMI整流二极管1N5408

DS1302的电子万年历_51单片机,年月日、星期、时分秒、农历和温度,带闹钟,全套资料

OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示

编程哲学——自动加载、依赖注入与控制反转

On the insecurity of using scanf in VS

一个月把字节,腾讯,阿里都面了,写点面经总结……

ArrayList collection basic usage

MySQL报错packet out of order
随机推荐
Epoll's et, lt working mode -- example program
AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
Sed learning for application
JumpServer
PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
关于在vs中使用scanf不安全的问题
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
【Servlet】Servlet 详解(使用+原理)
你还不知道责任链模式的使用场景吗?
抑郁症治疗的进展
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
单片机的函数信号发生器,输出4种波形,频率可调,原理图,仿真和C程序
压缩映射定理
Chapter 7 of JVM series -- bytecode execution engine
Parameter stack pressing problem of C language in structure parameter transmission
QT actual combat: Yunxi chat room
《JVM系列》 第七章 -- 字节码执行引擎
GIS数据处理-cesium中模型位置设置
Four ways of SSH restricting login