china-pub  
您的位置:china-pub网上书店 > 计算机 > c语言的头文件注意事项

c语言的头文件注意事项

    c语言的头文件编写时有哪些注意事项呢?尤其是单片机程序编写。

案例:

shumaguan.h 文件里:

/*--------------------------------------------------------------------------
shumaguan.H

--------------------------------------------------------------------------*/

#ifndef __SHUMAGUAN_H__
#define __SHUMAGUAN_H__

#pragma SAVE
#pragma REGPARMS
extern void shumaguan_init();
extern void shumaguan_show(float k);
extern void shumaguan_f(float n);
extern void shumaguan_c(char b,char c);

#pragma RESTORE

#endif

 

c语言的头文件shumaguan.c 文件里:

 

//4位共阳数码管  
#include
unsigned char const num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit n1=P2^0;   // 数码管低位
sbit n2=P2^1;
sbit n3=P2^2;
sbit n4=P2^3;
#define Data  P1    //数据端口
unsigned char  s[5]={0xff,0xff,0xff,0xff,0xff};
void delay()
{
      unsigned int i;
      for(i=0;i<500;i++);
}
void shumaguan_init()
{
    n1=1;
    n2=1;
    n3=1;
    n4=1;    
 }
void shumaguan_show(float k)  //k< 0,数码管最高位显示负号,K>0则显示数字

 

   首先要把函数声明在.h文件里面,然后把函数写在.c文件里面,注意文件名要一样,而且不要把.c文件添加到工程里面,只要在程序开始时声明调用.h文件就可以了

  

分享到:
上一篇:c语言国外经典书籍推荐
下一篇:c语言的特点

推荐图书频道