bdata across multiple files?

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;
}

Parents
  • As Alex has already said, you need sbit, not sfr

    and then:

    // main.h
    extern char bdata Main_Bits;
    extern bit        Main_Bit0;

    //main.c 
    #include "main.h"
    
    char bdata Main_Bits;
    sbit       Main_Bit0 = Main_Bits ^ 0;

    In the header file, you just declare that Main_Bit0 is a bit which is defined elsewhere;
    In main.c, you actually define the actual storage location of the bit.

    Note also that bits always have to be at "global" scope - you can't have local bit variables within functions.

    This is not well documented in the Keil manuals - it took me a while to get to grips with it!

    As mentioned elsewhere, it doesn't hurt to #include "main.h" in main.c, and it does give you the advantage that the compiler will complain if your declarations & definitions get out of step!








Reply
  • As Alex has already said, you need sbit, not sfr

    and then:

    // main.h
    extern char bdata Main_Bits;
    extern bit        Main_Bit0;

    //main.c 
    #include "main.h"
    
    char bdata Main_Bits;
    sbit       Main_Bit0 = Main_Bits ^ 0;

    In the header file, you just declare that Main_Bit0 is a bit which is defined elsewhere;
    In main.c, you actually define the actual storage location of the bit.

    Note also that bits always have to be at "global" scope - you can't have local bit variables within functions.

    This is not well documented in the Keil manuals - it took me a while to get to grips with it!

    As mentioned elsewhere, it doesn't hurt to #include "main.h" in main.c, and it does give you the advantage that the compiler will complain if your declarations & definitions get out of step!








Children
No data
More questions in this forum