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

Reading/Writing external memory using xdata

I like to know how to read external memory using xdata .I've tried like this

unsigned char xdata *PORTA=0X8000;
unsigned char xdata *CW=0X8003;
unsigned char  val2, val3;
val2=0X80;
CR=&val2;
val3=0X50;
PORTA=&val3;
but I'm not getting the expected output..Pls suggest.
Thanks & Regards,
Reny.

Parents
  • You seem to be confused about the basic 'C' concepts of pointers - look up the dereference operator '*' and the address-of operator '&' in a 'C' textbook.

    unsigned char xdata *PORTA=0X8000;
    PORTA is a pointer to a byte in XDATA; the pointer's value is 0x8000 - that is, the pointer is pointing to X:0x8000.
    PORTA=&val3;
    This takes the address of the variable val3, and assigns it to the pointer PORTA - so PORTA is no longer pointing to X:0x8000, but to somewhere completely different.

    Presumably, you actually want to write the value of val3 into XDATA address 0x8000?

    See: http://www.keil.com/forum/docs/thread6175.asp

Reply
  • You seem to be confused about the basic 'C' concepts of pointers - look up the dereference operator '*' and the address-of operator '&' in a 'C' textbook.

    unsigned char xdata *PORTA=0X8000;
    PORTA is a pointer to a byte in XDATA; the pointer's value is 0x8000 - that is, the pointer is pointing to X:0x8000.
    PORTA=&val3;
    This takes the address of the variable val3, and assigns it to the pointer PORTA - so PORTA is no longer pointing to X:0x8000, but to somewhere completely different.

    Presumably, you actually want to write the value of val3 into XDATA address 0x8000?

    See: http://www.keil.com/forum/docs/thread6175.asp

Children
No data