1.新建一个Delay.c文件和Delay.h文件
2.Delay.c中,Delay函数代码如下:(11.0592MHz,可以由stc软件自带的计算器计算出来)
//Delay函数模块化
void Delay(unsigned int xms) //Delay Function @11.0592MHz
{unsigned char i, j;for(;xms>0;xms--){i = 2;j = 199;do{while (--j);} while (--i);}
}
3.配置Delay.h文件,代码如下:
#ifndef __DELAY_H__
#define __DELAY_H__void Delay(unsigned int xms);#endif
4.在main函数头部分引用头文件
#include "Delay.h"