我在TypeDefine.h头文件中定义了一个类型,代码如下: #ifndef DATA_TYPE #define DATA_TYPE
#define uint unsigned int #define uchar unsigned char #define ulong unsigned long
typedef union { struct { unsigned char b0: 1; unsigned char b1: 1; unsigned char b2: 1; unsigned char b3: 1; unsigned char b4: 1; unsigned char b5: 1; unsigned char b6: 1; unsigned char b7: 1; }bit_def; uchar all; }byte_def;
#define ubat_fault_value 108 #define setbit(var,bit) (var|=(0x01<<(bit))) #define clrbit(var,bit) (var&=(~(0x01<<(bit)))) #define checkbit(var,bit) (var&(0x01<<(bit)))
#define CHNL_1 RA5=0,RA4=0,RA2=0 #define CHNL_2 RA5=0,RA4=0,RA2=1 #define CHNL_3 RA5=0,RA4=1,RA2=0 #define CHNL_4 RA5=0,RA4=1,RA2=1 #define CHNL_5 RA5=1,RA4=0,RA2=0 #define CHNL_6 RA5=1,RA4=0,RA2=1 #define CHNL_7 RA5=1,RA4=1,RA2=0 #define CHNL_8 RA5=1,RA4=1,RA2=1 #define BUZZ_RING RC3=1 #define BUZZ_OFF RC3=0
#define LED_OFF RC1=1 #define LED_ON RC1=0 #define KEY RC2
#define Enable_Int GIE=1,PEIE=1 #define Disable_Int GIE=0,PEIE=0
#define CHARGE_OPEN RC4 #define CHARGE_SHORT RC5 #define OUT1_OPEN RB0 #define OUT1_SHORT RB1 #define OUT2_OPEN RB2 #define OUT2_SHORT RB3 #define OUT3_OPEN RB4 #define OUT3_SHORT RB5 #define OUT4_OPEN RB6 #define OUT4_SHORT RB7
#endif 在Battery Check.h头文件中声明了fault_battery、ubat、n_bat、n_fault这四个变量,代码如下: #ifndef BATTERY_DEF #define BATTERY_DEF
#if 1==BATTERY_OP #define BATTERY_EXT #else #define BATTERY_EXT extern #endif
#include <pic.h> #include "TypeDefine.h"
BATTERY_EXT byte_def fault_battery; #define fault fault_battery.all #define f1 fault_battery.bit_def.b0 #define f2 fault_battery.bit_def.b1 #define f3 fault_battery.bit_def.b2 #define f4 fault_battery.bit_def.b3 #define f5 fault_battery.bit_def.b4 #define f6 fault_battery.bit_def.b5 #define f7 fault_battery.bit_def.b6 #define f8 fault_battery.bit_def.b7
BATTERY_EXT uchar ubat,n_bat,n_fault;
BATTERY_EXT void AD_Intial(void); BATTERY_EXT void fault_check(void);
#endif 在Battery Check.c中定义这些变量: #define BATTERY_OP (1)
#include "Battery Check.h" #include "Interrupt.h"
void AD_Intial(void) { TRISA = 0x37; //RA0,RA1,RA2,RA4,RA5:input PORTA = 0x00; ADCON1 = 0x05; //RA0,RA1 are used as analog input,RA3 is Vref. ADCON0 = 0x40; //A/D conversion clock is Fosc/8,Fosc=4MHz. uchar ubat=0x00,n_bat=1,n_fault=0x00; byte_def fault_battery=0x00; } 编译提示: Executing: "C:\HT-PIC\BIN\PICC.EXE" -C -E"Main.cce" "Main.c" -O"Main.obj" -I"C:\HT-PIC\include" -Zg9 -O -ASMLIST -Q -MPLAB -16F73 Executing: "C:\HT-PIC\BIN\PICC.EXE" -C -E"Battery Check.cce" "Battery Check.c" -O"Battery Check.obj" -I"C:\HT-PIC\include" -Zg9 -O -ASMLIST -Q -MPLAB -16F73 Error[000] E:\microchip\C Language\Battery Check.c 13 : probable missing '}' in previous block Error[000] E:\microchip\C Language\Battery Check.c 15 : no identifier in declaration Warning[000] E:\microchip\C Language\Battery Check.c 15 : missing basic type: int assumed Error[000] E:\microchip\C Language\Battery Check.c 15 : ; expected Halting build on first failure as requested. BUILD FAILED: Thu Apr 12 13:42:44 2007 这是为什么?程序书写没有问题啊! 我第一次用PICC编译器,希望各位大虾指点!多谢! |