The relationship and difference between .c file and .h file in 51 single chip C

C files are an important concept in programming. A "file" generally refers to a collection of data stored on an external medium. A batch of files is stored on external media (such as a disk) in the form of data. The operating system manages data in units of files. That is, if you want to find data on an external medium, you must first find the specified file by file name and then read the data from the file.

Documents are an important concept in programming. A "file" generally refers to a collection of data stored on an external medium. A batch of files is stored on external media (such as a disk) in the form of data. The operating system manages data in units of files. That is, if you want to find data on an external medium, you must first find the specified file by file name and then read the data from the file. To store data on external media, you must first create a file (identified by the file name) in order to output data to it.

The relationship and difference between .c file and .h file in 51 single chip C

1) h file function

1 Convenient development: contains common constants, structures, type definitions, functions, variable declarations required by some files;

2 Provide interface: For a software package, you can provide an interface to the outside world (for example: stdio.h).

2) What should be in the h file?

Constants, structures, type definitions, functions, variable declarations.

3) The h file should not have any variable definitions, function definitions.

4) extern problem requires extern for variables;

It is not necessary for functions because the default state of the function is extern. If a function is to be changed to be visible only within the file, add staTIc.

5) include contains questions

Although declarations and type definitions can be repeated, it is recommended to use conditional compilation. #ifndef_FILENAME_H #define_FILENAME_H ...... #endif

6) should include the h file there

Where it is needed. For example, a h file that provides an interface is only needed by the 1.c file, so it is included in the 1.c file.

The program written generally has a .H file and a corresponding .C file. The .H file is used for declarations, and the .C file is part of its function implementation. As long as the .H file is included in the call, we have not heard of programs such as #include "delay.c", and we do not advocate the use of this form.

In the delay.h file: //Declare the function called #ifndef__DELAY_H__ #define__DELAY_H__

externvoidDelayms(unsigned int n); #endif

In the delay.c file: // function implementation part #include

//for crystal11.0592M

voidDelayms(unsigned int n) {

unsignedinTI,j; for(j=n;j"0;j--) for(i=112;i"0;i--);

In the main program main.c

#include //The .h file is included in the main program and cannot contain .c files...

The above method still requires that each built project needs to copy the corresponding header file into the project folder, which seems to be still cumbersome. At this time, another method is to put the prepared header file in one. In the folder, then copy this folder as a whole. .KEILC51INC below, if you need to use a header file in the future, it is as convenient as using the header file that comes with KEIL. Before the main function mani(), there is a #include to use the function in main().

R and M

Randm Tornado Vape,Randm Tornado Disposable,Randm Disposable Vape,Randm Tornado Vape Pod

Nanning Nuoxin Technology Co., LTD , https://www.nx-vapes.com

Posted on