如下代碼是單片機程序,51單片機,編譯器爲HT-IDE3000,函數
簡單來講spa
頭文件中只能申明,code
變量在頭文件中申明時,要加上extern 這個關鍵字用來告訴編譯器,變量在其它的文件中定義,爲何要在頭文件中申明變量?---------->由於想在其它文件裏的代碼中使用這些變量,blog
如在a.c中使用b.c裏定義的變量,編譯器
enum 不是變量,是咱們本身定義的數據類型,像int char 同樣,只不過是咱們本身定義的,因此不用加,編譯
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;//中間變量 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;
函數也在頭文件中,也只能申明,不能加函數體class
u8 UART_Receive();
變量和函數的實現也就是函數體,只能在源文件中定義變量
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;//中間變量 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 //===========================數據接收=========================================// 29 u8 UART_Receive() 30 { 31 u8 data; 32 if(_rxif==1)//若是接收到數據 33 { 34 data=_txr_rxr; 35 return data; 36 } 37 }