I have data that I would like to efficiently address as both a byte and as 8 bits. The bdata type sounds like the way to go, but I can not make it work across multiple files. This program fails to compile and link. Any ideas?
// main.h extern char bdata Main_Bits; sfr Main_Bit0 = Main_Bits ^ 0;
//main.c #include "main.h" char bdata Main_Bits; void FnA( void ); void main( void ) { Main_Bits = 0; FnA(); }
//FnA.c #include "main.h" void FnA( void ) { Main_Bit0 = 1; }
Sorry, I really did mean to type sbit. Anyways, using sbit, I get the following errors.
Build target 'Target1' compiling Main.C... MAIN.H(3): error C142: 'Main_Bits': invalid base address compiling FnA.c... MAIN.H(3): error C142: 'Main_Bits': invalid base address .\FNA.C(5): error C202: 'Main_Bit0': undefined identifier Target not created
// main.h extern char bdata Main_Bits; sbit Main_Bit0 = Main_Bits ^ 0;
See my earlier post: you need just an "extern bit" (not sbit) declaration in the header file, and the sbit definition in the main.c file
Thank you very much. I would never have thought to use an "extern bit" for a "sbit declaration".
You're not alone! I had the same trouble, and everyone else at this Client as well! Like I said, this is poorly documented in the Keil manuals.
Refer to page 328 in the C51 users guide 01.97. The description shows how to deal with bits in bdata memory. HHK
Yes, that's what I meant by it being poorly documented (it didn't say it wasn't documented!) <RANT> Why is this information hidden away in an appendix right at the back of the manual instead of being clearly stated in the main body? This is one of Keil's extensions to ANSI 'C' - you won't find it in any "general" 'C' textbook, so if you can't get a clear explanation from the manual, where on earth is it going to come from!? IMO, The fact that they have felt the need to include this section just goes to prove that the body of the manual is inadequate! </RANT> Fortunately, we have this discussion forum!