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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
AFAIK this isn't possible.
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.
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