We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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;
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; }