Hello all, I'm having problem declaring bit as global in header file to avoid including extern bit xxx in other files. I've followed Keil instruction from this link: http://www.keil.com/support/docs/1868.htm
So far all the variables are good, and I don't have to use extern type variable xxx any more. For bit I try to do this:
_DECL bit xxx _INIT(x);
but it doesn't work. Is there any way to get it through? Would it be good to use struct in this case? If so, how should I do this? Any inputs would be greatly appreciated.
Best Regards, T.L
Hello Erik
_DECL unsigned char Capt_0_H _INIT(0);
the _INIT (0) part according to the link from Keil in my first post is to set initial value of that variable. In this case Capt_0_H is set to 0x00.
<i_DECL unsigned char Capt_0_H _INIT(0);
I do not get it (something like _DECL is quite common) but what the ... is _INIT(0)
Erik
Hans, Thank you for your input, and sorry for being late. I just get back to work this morning. This is what I did in the header file called Vars_Defs.h and this file is included in a Post.c using #include <Vars_Defs.h>
#ifndef VAR_DEFS #define VAR_DEFS 1 #ifndef VAR_DECLS # define _DECL extern # define _INIT(x) #else # define _DECL # define _INIT(x) = x #endif _DECL unsigned char Capt_0_H _INIT(0); _DECL unsigned char Capt_0_L _INIT(0); _DECL unsigned char Capt_1_H _INIT(0); _DECL unsigned char Capt_1_L _INIT(0); _DECL unsigned char Er0_H_Pos _INIT(0); _DECL unsigned char Er0_L_Pos _INIT(0); _DECL unsigned char Er0_H_Neg _INIT(0); _DECL unsigned char Er0_L_Neg _INIT(0); _DECL unsigned char Er1_H_Pos _INIT(0); _DECL unsigned char Er1_L_Pos _INIT(0); _DECL unsigned char Er1_H_Neg _INIT(0); _DECL unsigned char Er1_L_Neg _INIT(0); _DECL unsigned char Err_A _INIT(0); _DECL unsigned char Err_B _INIT(0); _DECL unsigned char Capt_Good_A _INIT(0); _DECL unsigned char Capt_Good_B _INIT(0); _DECL unsigned char A_Setpoint _INIT(0); _DECL unsigned char A_Set_half _INIT(0); _DECL unsigned char B_Setpoint _INIT(0); _DECL unsigned char B_Set_half _INIT(0); _DECL unsigned char A_Current _INIT(0); _DECL unsigned char B_Current _INIT(0); _DECL bit Capt_Done _INIT(0); _DECL bit Toggle_flag _INIT(0); _DECL bit Dual_flag _INIT(0); _DECL bit AB_On _INIT(0); _DECL bit Ready _INIT(0); #endif
and here is the warning message, not error:
Build target 'Target 1' compiling Main.c... compiling Post.c... linking... *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: CAPT_DONE MODULE: Post.obj (POST) *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: READY MODULE: Post.obj (POST) *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: READY MODULE: Post.obj (POST) ADDRESS: 00A5H *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: CAPT_DONE MODULE: Post.obj (POST) ADDRESS: 00A8H *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: CAPT_DONE MODULE: Post.obj (POST) ADDRESS: 00D5H *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: READY MODULE: Post.obj (POST) ADDRESS: 00ECH Program Size: data=13.4 xdata=0 code=454 "DigitalFS" - 0 Error(s), 6 Warning(s).
If I comment out the bit part in header file and make them global in Main.c and use extern bit directive in Post.c then no more warning like this
Build target 'Target 1' compiling Main.c... compiling Config.c... compiling Delay.c... compiling A2d.c... compiling Post.c... assembling STARTUP.A51... linking... Program Size: data=14.1 xdata=0 code=454 "DigitalFS" - 0 Error(s), 0 Warning(s).
but it doesn't work.
There's no way anyone can help you based on a problem description that vague. Be specific. Show what exactly you tried, and how exactly it failed. A complete, reproducible example input and error log would be best.
View all questions in Keil forum