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

Internal XDATA

I have an existing design with external RAM mapped from 0000 and a lot of units manufactured. To rectify some intermittent errors in the original code, I need to gain a bit more RAM without modifying the hardware, so I want to use a chip with some internal XDATA memory in it.
1) How do I define which variables are in internal XDATA and which are in external XDATA since the addresses are the same, and MOVX is used in either case.
2) How do I specify the switch mechanism between internal and external XDATA since they are chip dependent (I know that e.g. Winbond and Philips use different mechanisms).

Erik

Parents
  • Question 2 first -

    If you can decide which is the target at compile time use a compiler flag to allow either set of code to be compiled. If you need to decide at run time, you have to discover a way to differentiate between the two chips and then use an if statement to steer accordingly.

    Question 1 - This is more difficult. You can assign two variables to the same location using the _at_ directive, but you will get warnings at link time. If you can live with this, at least it allows you multiple variable names accessing the same location.

    If not, you'd have to define a single variable, and then just access it by that name. You will get no warnings, but some of your functions may use variable names that sound peculiar. You could get around this by creating a macro that gives an equivalent name :

    extern void dataselect1(void);
    extern void dataselect2(void);
    
    extern char xdata abc;  // data space 1
    #define xyz abc         // data space two
    
    void main (void)
    {
      char  xdata aaa;
      
      dataselect1();        //select the first data space
      aaa = abc;
      dataselect2();
      aaa = xyz;
    
    }
    



Reply
  • Question 2 first -

    If you can decide which is the target at compile time use a compiler flag to allow either set of code to be compiled. If you need to decide at run time, you have to discover a way to differentiate between the two chips and then use an if statement to steer accordingly.

    Question 1 - This is more difficult. You can assign two variables to the same location using the _at_ directive, but you will get warnings at link time. If you can live with this, at least it allows you multiple variable names accessing the same location.

    If not, you'd have to define a single variable, and then just access it by that name. You will get no warnings, but some of your functions may use variable names that sound peculiar. You could get around this by creating a macro that gives an equivalent name :

    extern void dataselect1(void);
    extern void dataselect2(void);
    
    extern char xdata abc;  // data space 1
    #define xyz abc         // data space two
    
    void main (void)
    {
      char  xdata aaa;
      
      dataselect1();        //select the first data space
      aaa = abc;
      dataselect2();
      aaa = xyz;
    
    }
    



Children