1, input and output interface function declaration such as extern void InitLcd1602 ();
2. Global variable declaration
3. declaring A custom data type: struct, enum-body
typedef SIGNED char int8;
Main.h
#ifndef _main_h#define _main_henum estasystem { e_normal, e_set_time, e_set_alarm};# ifndef _main_cexternenum estasystem Stasystem; #endif void 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; enumEstasystem Stasystem = E_normal;//ïµí³ôëððx´ì¬voidMain () {
//generic header file, each. C Reference#ifndef _config_h#define_config_h/*ͨóãí Îä¼þ*/#include<reg52.h>#include<intrins.h>/*Êý¾ýààðí¶¨òå*/typedef signedCharint8;//8î»óð Ûºåõûðíêýtypedef signedintInt16;//16î»óð Ûºåõûðíêýtypedef signedLongInt32;//32î»óð Ûºåõûðíêýtypedef unsignedCharUint8;//8î»îþ Ûºåõûðíêýtypedef unsignedintUInt16;//16î»îþ Ûºåõûðíêýtypedef unsignedLongUInt32;//32î»îþ Ûºåõûðíêý/*È«¾öôëðð²îêý¶¨òå*/#defineSYS_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ïôê¾²¿¼þµäxüê¹äüòý½å#definelcd1602_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;//I2cxüïßê±öóòý½åSbit I2C_SDA = p3^6;//I2cxüïßêý¾ýòý½åSbit Buzzer= p1^6;//• Äãùæ÷¿øöæòý½åsbit Io_18b20= p3^2;//Ds18b20í¨ðåòý½åsbit ir_input= p3^3;//ºìíâ½óêõòý½å#endif
--procedure quoted from Golden Beach Studio
Someone has said:
"How do we differentiate between global variables, which are definition declarations, and which are reference declarations?" This is more complex than a function, generally in C language, there are several models to differentiate:
1. Initialize the statement model
In the top-level declaration, there is an initialization statement that indicates that the declaration is a definition declaration, and that the other declaration is a reference declaration. There can be only one definition declaration in all C language files.
According to this model, we can define the following Tpye g_test=1 in the first.h, so it is OK to define the declaration in first, and all other declarations are reference declarations.
2 , Omit storage type description
In this model, all the reference declarations to be displayed include the storage class extern , The storage-class specifier is omitted from the unique definition declaration for each external variable. "--quoting the http://www.cnblogs.com/light-wind/archive/2012/11/25/c_1.html of the bloggers ' itinerant winds
What should be written in the header file?