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

Addressing External Memory

Hello,

BASE_ADDR = 0x8000
i=1

A)may I know what is
#define COMMAND(i) (*((volatile char xdata *)(BASE_ADDR +i)))

B)Is is better to address the "command register" of an external chip as XDATA of 8051 chip(using ALE,Port0,Port2,etc) or should I just manually arrange some I/O pins (of 8051) to do that?

Regards,
KC

Parents
  • 1) Is "COMMAND(i)" a "memory specific pointer"?
    yes
    2) Does it take up any memory space (eg 2bytes as you would expect of a memory specific pointer)?
    look in the generated assembly
    3) Is there a better way (or clearer code) to do this?
    many ways, I would name the memory mapped I/Os individually and use
    #define SOME_COMMAND_ADDR (BASE_ADDR +nnn)
    xdata volatile SOME_COMMAND _at_ SOME_COMMAND_ADDR
    or something like that
    4) Is the "volatile" really necessary? (or should i do some settings to prevent optimization from affecting code)
    Volatile works for this, why reinvent the wheel.

    Erik

Reply
  • 1) Is "COMMAND(i)" a "memory specific pointer"?
    yes
    2) Does it take up any memory space (eg 2bytes as you would expect of a memory specific pointer)?
    look in the generated assembly
    3) Is there a better way (or clearer code) to do this?
    many ways, I would name the memory mapped I/Os individually and use
    #define SOME_COMMAND_ADDR (BASE_ADDR +nnn)
    xdata volatile SOME_COMMAND _at_ SOME_COMMAND_ADDR
    or something like that
    4) Is the "volatile" really necessary? (or should i do some settings to prevent optimization from affecting code)
    Volatile works for this, why reinvent the wheel.

    Erik

Children
No data