This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

89C51 with internal XRAM and EEPROM

I am using an 89C51 variant with both intenal XRAM and EEPROM and as such their address space overlaps from 0x0000 to 0x03FF so I have variables declared as follows:-

#define size 0x20

/* variables to be stored in xdata */
char xdata cArray[size];
int xdata iTimer;

/* variables to be stored in EEPROM */
char xdata cEE_Array _at_ 0x00; /* config data copied to/from cArray */
int xdata iEE_Timer _at_ 0x20;

My problem is that if i redefine 'size' later I have to recalculate where variables are '_at_' in EEPROM. Assuming that other than ensuring that enough space is left between variable declarations to allow for any future changes, is there any way of getting rid of the '_at_' definitions and getting the compiler/linker to sort out the address within the EEPROM the variables are?

Thanks,
Mark.

Please Note I have C51 ver 7.XX and cannot upgrage to the package allowing RAM bank switching.

  • You really have two different memory spaces, your XRAM and EEPROM.

    I'd suggest making two different .c files, so that you get two different segments. You can then tell the linker where to put the segments. It will no doubt complain that the segments overlap.

    Alternatively, you might just declare a big struct to hold your EEPROM configuration layout and access it it via a pointer. You'll probably also want to wrap your RAM / EEPROM swapping functions so that they are always paired, and you don't accidentally leave your EEPROM mapped in while you're executing code that needs variables in the xdata RAM.


    Something like:

    typedef struct
        {
        U8 EE_Array[32];
        U16 EE_Timer;
        } EepromConfig;
    
    #define Config   ((const EepromConfig xdata*)0x0000)
    
    U16 GetEeTimer (void)
        {
        U16 result;
    
        SwapInEeprom();
        result = Config->EE_Timer;
        SwapOutEeprom();
    
        return result;
        }