The following code is a single-chip program, 51 single-chip, compiler HT-IDE3000,
Simply speaking
The header file can only state,
When variables are declared in the header file, the keyword extern should be added to tell the compiler that variables are defined in other files,
enum is not a variable, but a data type defined by ourselves. Like int char, it's just defined by ourselves, so we don't need to add,
1 extern u16 g_u16TimeBaseCount; 2 extern u8 g_8count_2s; 3 extern u8 g_8count_8s; 4 extern u8 g_8count_18s; 5 extern u8 g_8count_60s; 6 extern u8 g_8count_200s; 7 extern u8 g_8count_6h; 8 extern u8 g_8count_200sw;//6hour wash 9 extern u8 g_8count_6hw;//6hour wash 10 extern u8 w_6hw_start; 11 extern u8 w_6hw_end; 12 extern u8 g_state; 13 extern u16 make_6h_count; 14 extern u8 g_once; 15 extern u16 s_c1;//Intermediate variable 16 extern u16 s_c2; 17 extern u16 s_c3; 18 extern u16 s_c4; 19 20 extern u8 UARTReceive; 21 extern u8 AD[6]; 22 extern u8 TDS[6]; 23 extern u8 count_AD; 24 extern u8 count_ADS; 25 extern u16 sumTDS_H,sumTDS_L,sum; 26 extern u16 temer; 27 28 typedef enum GPIOPin 29 { 30 GPIO_Pin_0 = ((u8)0x01), /*!< Pin 0 selected */ 31 GPIO_Pin_1 = ((u8)0x02), /*!< Pin 1 selected */ 32 GPIO_Pin_2 = ((u8)0x04), /*!< Pin 2 selected */ 33 GPIO_Pin_3 = ((u8)0x08), /*!< Pin 3 selected */ 34 GPIO_Pin_4 = ((u8)0x10), /*!< Pin 4 selected */ 35 GPIO_Pin_5 = ((u8)0x20), /*!< Pin 5 selected */ 36 GPIO_Pin_6 = ((u8)0x40), /*!< Pin 6 selected */ 37 GPIO_Pin_7 = ((u8)0x80), /*!< Pin 7 selected */ 38 GPIO_Pin_LNib = ((u8)0x0F), /*!< Low nibble pins selected */ 39 GPIO_Pin_HNib = ((u8)0xF0), /*!< High nibble pins selected */ 40 GPIO_Pin_All = ((u8)0xFF) /*!< All pins selected */ 41 }GPIO_Pin_TypeDef;
The function is also in the header file. It can only be stated that the function body cannot be added
u8 UART_Receive();
The implementation of variables and functions is the function body, which can only be defined in the source file
1 uFlg uF1,uF2,uF3,uF4; 2 u16 g_u16TimeBaseCount; 3 u8 g_8count_2s; 4 u8 g_8count_8s; 5 u8 g_8count_18s; 6 u8 g_8count_60s; 7 u8 g_8count_200s; 8 u8 g_8count_6h; 9 u8 g_8count_200sw;//6hour wash 10 u8 g_8count_6hw;//6hour wash 11 u8 w_6hw_start; 12 u8 w_6hw_end; 13 u8 g_state; 14 u16 make_6h_count; 15 u8 g_once; 16 u16 s_c1;//Intermediate variable 17 u16 s_c2; 18 u16 s_c3; 19 u16 s_c4; 20 u8 UARTReceive=0; 21 u8 AD[6]={0,0,0,0,0,0}; 22 u8 TDS[6]={0,0,0,0,0,0}; 23 u8 count_AD=0; 24 u8 count_ADS=0; 25 u16 sumTDS_H=0,sumTDS_L=0,sum=0; 26 u16 temer; 27 28 //===========================Data reception=========================================// 29 u8 UART_Receive() 30 { 31 u8 data; 32 if(_rxif==1)//If data is received 33 { 34 data=_txr_rxr; 35 return data; 36 } 37 }