8-bit pointer to XDATA

Help
Anonymous
2002-12-20
2013-03-12
  • Anonymous - 2002-12-20

    How should I declare a pointer to char (*char) to implement an access to the external RAM using 8 bit address, like in " movx   a,@r0 " ?

    Thanks.

     
    • Bernhard Held

      Bernhard Held - 2002-12-20

      AFAIK this isn't possible.

       
    • stefan stefanov

      stefan stefanov - 2005-03-01

      I use this:

      unsigned char buf[5]={1,2,3,4,5};
      union {
        char *cbuf;
        unsigned char ccbuf;
      } c;

      void main(void) {
        c.cbuf=&buf[0];
        some_function(c.ccbuf,sizeof(buf));

      etc.

       
    • Maarten Brock

      Maarten Brock - 2005-03-03

      Stefan,

      You did not specify in which memory buf should reside (data/idata/xdata/code). Are you assuming large memory model? cbuf is a generic pointer which has a size of three bytes. You union that with a single char ccbuf. Allthough ccbuf contains the LSB of the address in cbuf, it's still no 8-bit xdata pointer which we call pdata pointer.

      Somewhere during the last year pdata has been made to work. To allocate a variable in pdata and implicitly access it using 8-bit pointers (movx @Ri) you use:
      pdata char x;
      x = 1; //or whatever
      To explicitly access it using an 8-bit pointer you use:
      pdata char *p = &x;
      *p = 2;
      The pdata segment has a maximum size of 256 bytes. If you want to access anything else in xdata using 8-bit pointers, you use:
      xdata char y;
      union {
        xdata char * py;
        struct {
          pdata char *lo;
          unsigned char hi;
        } b;
      } c;
      c.py = &y;
      unsigned char SavePage = _XPAGE;
      _XPAGE = c.b.hi; //to select the page
      *c.b.lo = 3;
      _XPAGE = SavePage;

      During the time you have changed the value of _XPAGE you must take care not to access anything in pdata or on the xstack.

      Hope this clears things up a bit,
      Maarten Brock

       

Log in to post a comment.