1、输入输出接口函数声明如extern void InitLcd1602();
2、全局变量声明
3、声明自定义数据类型:结构体,枚举体
typedef signed char int8;
main.h #ifndef _MAIN_H#define _MAIN_Henum eStaSystem { E_NORMAL, E_SET_TIME, E_SET_ALARM};#ifndef _MAIN_Cextern enum eStaSystem staSystem;#endifvoid RefreshTemp(uint8 ops);void ConfigTimer0(uint16 ms);#endif
main.c #define _MAIN_C#include "config.h"#include "Lcd1602.h"#include "LedBuzzer.h"#include "keyboard.h"#include "DS1302.h"#include "DS18B20.h"#include "Infrared.h"#include "Time.h"#include "main.h"bit flag2s = 0; bit flag200ms = 0;uint8 T0RH = 0; uint8 T0RL = 0; enum eStaSystem staSystem = E_NORMAL; //ϵͳÔËÐÐ״̬void main(){
//通用头文件,每个.c都引用#ifndef _CONFIG_H#define _CONFIG_H/* ͨÓÃÍ·Îļþ */#include#include /* Êý¾ÝÀàÐͶ¨Òå */typedef signed char int8; // 8λÓзûºÅÕûÐÍÊýtypedef signed int int16; //16λÓзûºÅÕûÐÍÊýtypedef signed long int32; //32λÓзûºÅÕûÐÍÊýtypedef unsigned char uint8; // 8λÎÞ·ûºÅÕûÐÍÊýtypedef unsigned int uint16; //16λÎÞ·ûºÅÕûÐÍÊýtypedef unsigned long uint32; //32λÎÞ·ûºÅÕûÐÍÊý/* È«¾ÖÔËÐвÎÊý¶¨Òå */#define SYS_MCLK (11059200/12) //ϵͳÖ÷ʱÖÓƵÂÊ£¬¼´Õñµ´Æ÷ƵÂÊ¡Â12/* IOÒý½Å·ÖÅ䶨Òå */sbit KEY_IN_1 = P2^4; //¾ØÕó°´¼üµÄɨÃèÊäÈëÒý½Å1sbit KEY_IN_2 = P2^5; //¾ØÕó°´¼üµÄɨÃèÊäÈëÒý½Å2sbit KEY_IN_3 = P2^6; //¾ØÕó°´¼üµÄɨÃèÊäÈëÒý½Å3sbit KEY_IN_4 = P2^7; //¾ØÕó°´¼üµÄɨÃèÊäÈëÒý½Å4sbit KEY_OUT_1 = P2^3; //¾ØÕó°´¼üµÄɨÃèÊä³öÒý½Å1sbit KEY_OUT_2 = P2^2; //¾ØÕó°´¼üµÄɨÃèÊä³öÒý½Å2sbit KEY_OUT_3 = P2^1; //¾ØÕó°´¼üµÄɨÃèÊä³öÒý½Å3sbit KEY_OUT_4 = P2^0; //¾ØÕó°´¼üµÄɨÃèÊä³öÒý½Å4sbit ADDR0 = P1^0; //LEDλѡÒëÂëµØÖ·Òý½Å0sbit ADDR1 = P1^1; //LEDλѡÒëÂëµØÖ·Òý½Å1sbit ADDR2 = P1^2; //LEDλѡÒëÂëµØÖ·Òý½Å2sbit ADDR3 = P1^3; //LEDλѡÒëÂëµØÖ·Òý½Å3sbit ENLED = P1^4; //LEDÏÔʾ²¿¼þµÄ×ÜʹÄÜÒý½Å#define LCD1602_DB P0 //1602Òº¾§Êý¾Ý¶Ë¿Úsbit LCD1602_RS = P1^0; //1602Òº¾§Ö¸Áî/Êý¾ÝÑ¡ÔñÒý½Åsbit LCD1602_RW = P1^1; //1602Òº¾§¶ÁдÒý½Åsbit LCD1602_E = P1^5; //1602Òº¾§Ê¹ÄÜÒý½Åsbit DS1302_CE = P1^7; //DS1302ƬѡÒý½Åsbit DS1302_CK = P3^5; //DS1302ͨÐÅʱÖÓÒý½Åsbit DS1302_IO = P3^4; //DS1302ͨÐÅÊý¾ÝÒý½Åsbit I2C_SCL = P3^7; //I2C×ÜÏßʱÖÓÒý½Åsbit I2C_SDA = P3^6; //I2C×ÜÏßÊý¾ÝÒý½Åsbit BUZZER = P1^6; //·äÃùÆ÷¿ØÖÆÒý½Åsbit IO_18B20 = P3^2; //DS18B20ͨÐÅÒý½Åsbit IR_INPUT = P3^3; //ºìÍâ½ÓÊÕÒý½Å#endif
——程序引自金沙滩工作室
有人讲过:
“我们又如何区分全局变量哪个是定义声明,哪个是引用声明呢?这个比函数要复杂一些, 一般在C语言中有如下几种模型来区分:
1、 初始化语句模型
顶层声明中,存在初始化语句是,表示这个声明是定义声明,其他声明是引用声明。C语言的所有文件之中,只能有一个定义声明。
按照这个模型,我们可以在first.h中定义如下TPYE G_test=1;那么就确定在first中的是定义声明,在其他的所有声明都是引用声明。
2、 省略存储类型说明
在这个模型中,所有引用声明要显示的包括存储类extern, 而每个外部变量的唯一定义声明中省略存储类说明符。”——引用博主流窜的风http://www.cnblogs.com/light-wind/archive/2012/11/25/c_1.html