External Data Memory

External data memory can be read and written and is physically located external to the 8051 CPU. Access to external data is very slow when compared to access to internal data. This is because external data memory is accessed indirectly through the data pointer (DPTR) register which must be loaded with a 16-bit address before accessing the external memory.

There may be up to 64 KBytes of external data memory; though, this address space does not necessarily have to be used as memory. Your hardware design may map peripheral devices into the memory space. If this is the case, your program would access external data memory to program and control the peripheral. This technique is referred to as memory-mapped I/O.

There are two different data types in C51 with which you may access external data: xdata and pdata.

The xdata memory specifier refers to any location in the 64 KByte address space of external data memory.

The pdata memory type specifier refers to only 1 page or 256 bytes of external data memory. See the “Compact Model” section under “Memory Models” later in this chapter for more information on pdata.