可以调用其他文件的函数
假如你想在main.c里调用driver.c里的函数
- 此时你需要创建一个driver.h,并写入
#ifndef _driver_h //先测试_driver_h 是否被宏定义过
#define _driver_h
code1 //如果_driver_h 没有被宏定义过,定义x,并编译code 1
#endif
code2 //如果_driver_h 已经定义过了则编译程序段2的语句,“忽视”code 1
这句话可以避免:如果在driver.h文件中定义了全局变量,main.c如果包含driver.h文件多次,会导致重复定义的错误
2.在driver.c和main.c里都写入
#include "driver.h"
3.假如你在driver.c里写了这么个子函数
void delay(int time)
{
while(--time)
{
_nop_();
}
}
那么你需要在driver.h里的code1处声明一下
#ifndef _driver_h
#define _driver_h
void delay(int time);
#endif
4此时直接在main.c调用即可