Absolute Memory Access Macros

The C51 standard library contains definitions for a number of macros that allow you to access explicit memory addresses. These macros are defined in ABSACC.H.  Each of these macros is defined to be used like an array.

CBYTE

The CBYTE macro allows you to access individual bytes in the program memory of the 8051 and is defined as follows:
#define CBYTE ((unsigned char *) 0x50000L)
You may use this macro in your programs as follows:
rval = CBYTE [0x0002];

to read the contents of the byte in program memory at address 0002h.

CWORD

The CWORD macro allows you to access individual words in the program memory of the 8051 and is defined as follows:
#define CWORD ((unsigned int *) 0x50000L)
You may use this macro in your programs as follows:
rval = CWORD [0x0002];

to read the contents of the word in program memory at address 0004h (2 × sizeof (unsigned int) = 4).

NOTE
The index used with this macro does not represent the memory address of the integer value. To obtain the memory address, you must multiply the index by the sizeof an integer (2 bytes).

DBYTE

The DBYTE macro allows you to access individual bytes in the internal data memory of the 8051 and is defined as follows:
#define DBYTE ((unsigned char *) 0x40000L)
You may use this macro in your programs as follows:
rval = DBYTE [0x0002];
DBYTE [0x0002] = 5;

to read or write the contents of the byte in internal data memory at address 0002h.

DWORD

The DWORD macro allows you to access individual words in the internal data memory of the 8051 and is defined as follows:
#define DWORD ((unsigned int *) 0x40000L)
You may use this macro in your programs as follows:
rval = DWORD [0x0002];
DWORD [0x0002] = 57;

to read or write the contents of the word in internal data memory at address 0004h (2 × sizeof (unsigned int) = 4).

NOTE
The index used with this macro does not represent the memory address of the integer value. To obtain the memory address, you must multiply the index by the sizeof an integer (2 bytes).

PBYTE

The PBYTE macro allows you to access individual bytes in one page of the external data memory of the 8051 and is defined as follows:
#define PBYTE ((unsigned char *) 0x30000L)
You may use this macro in your programs as follows:
rval = PBYTE [0x0002];
PBYTE [0x0002] = 38;

to read or write the contents of the byte in pdata memory at address 0002h.

PWORD

The PWORD macro allows you to access individual words in one page of the external data memory of the 8051 and is defined as follows:
#define PWORD ((unsigned int *) 0x30000L)
You may use this macro in your programs as follows:
rval = PWORD [0x0002];
PWORD [0x0002] = 57;

to read or write the contents of the word in pdata memory at address 0004h (2 × sizeof (unsigned int) = 4).

NOTE
The index used with this macro does not represent the memory address of the integer value. To obtain the memory address, you must multiply the index by the sizeof an integer (2 bytes).

XBYTE

The XBYTE macro allows you to access individual bytes in the external data memory of the 8051 and is defined as follows:
#define XBYTE ((unsigned char *) 0x20000L)
You may use this macro in your programs as follows:
rval = XBYTE [0x0002];
XBYTE [0x0002] = 57;

to read or write the contents of the byte in external data memory at address 0002h.

XWORD

The XWORD macro allows you to access individual words in the external data memory of the 8051 and is defined as follows:
#define XWORD ((unsigned int *) 0x20000L)
You may use this macro in your programs as follows:
rval = XWORD [2];
XWORD [2] = 57;

to read or write the contents of the word in external data memory at address 0004h (2 × sizeof (unsigned int) = 4).

NOTE
The index used with this macro does not represent the memory address of the integer value. To obtain the memory address, you must multiply the index by the sizeof an integer (2 bytes).