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"?

    No.
    A Pointer is a variable - you are defining an expression

    2) Does it take up any memory space (eg 2bytes as you would expect of a memory specific pointer)?

    No (apart from the code space necessary to evaluate the expression).
    COMMAND is a preprocessor definition - the macro is expanded by the preprocessor before the compiler ever sees it!

    3) Is there a better way (or clearer code) to do this?

    How about _at_, as Erik suggested?
    Or Keil's predefined XBYTE?

    4) Is the "volatile" really necessary?

    It's your system - only you can tell us that!

    ...should i do some settings to prevent optimization...

    No.
    This is precisely the situation for which volatile is provided - use it!

Reply
  • 1) Is "COMMAND(i)" a "memory specific pointer"?

    No.
    A Pointer is a variable - you are defining an expression

    2) Does it take up any memory space (eg 2bytes as you would expect of a memory specific pointer)?

    No (apart from the code space necessary to evaluate the expression).
    COMMAND is a preprocessor definition - the macro is expanded by the preprocessor before the compiler ever sees it!

    3) Is there a better way (or clearer code) to do this?

    How about _at_, as Erik suggested?
    Or Keil's predefined XBYTE?

    4) Is the "volatile" really necessary?

    It's your system - only you can tell us that!

    ...should i do some settings to prevent optimization...

    No.
    This is precisely the situation for which volatile is provided - use it!

Children
No data