Keil™, An ARM® Company

Cx51 User's Guide

XBANKING.A51

This file provides routines for far (HDATA) and far const (HCONST) memory type support. The extended LX51 linker/locator manages the extended address spaces HDATA and HCONST that are addressed with far and far const. The Cx51 Compiler uses a 3-byte generic pointer to access these memory areas.

Variables defined with the far memory type are placed in the memory class HDATA. Variables defined with const far get the memory class HCONST. The LX51 linker/locator allows you to locate these memory classes in the physical 16MB code or 16MB xdata spaces. To use far memory with the C51 Compiler for classic 8051 devices you must use the VARBANKING directive.

The memory types far and far const provide support for the large code/xdata spaces of new 8051 devices. If the MCU you are using provides an extended 24-bit DPTR register, you may adapt the default version of the file XBANKING.A51 and define the symbols listed in the following table.

NameDescription
?C?XPAGE1SFRSFR address of DPTR page register that contains DPTR bit 16-23.
?C?XPAGE1RSTReset value of the ?C?XPAGE1SFR to address the X:0 region. This setting used by the C51 compiler when you are using the VARBANKING(1) directive. With VARBANKING(1), the C51 compiler saves the ?C?XPAGE1SFR at the beginning of interrupt functions and sets this register to the ?C?XPAGE1RST value

The far memory type allows you to address special memory areas like EEPROM space or strings in code banking ROM. Your application accesses these memory areas as if they are a part of the standard 8051 memory space. Example programs in the folder C51\EXAMPLES\FARMEMORY show how to use the C51 far memory type on classic 8051 devices. If an example that fulfills your requirements is not provided, you may adapt the access routines listed in the table below.

Access RoutineDescription
?C?CLDXPTR, ?C?CSTXPTRload/store a BYTE (char) in extended memory.
?C?ILDXPTR, ?C?ISTXPTRload/store a WORD (int) in extended memory.
?C?PLDXPTR, ?C?PSTXPTRload/store a 3-BYTE pointer in extended memory.
?C?LLDXPTR, ?C?LSTXPTRload/store a DWORD (long) in extended memory.

Each access routine gets as a parameter the memory address in a 3-byte pointer representation in the MCU registers R1/R2/R3. The register R3 holds the memory type value. For classic 8051 devices, the Cx51 Compiler uses the following memory type values:

R3 ValueMemory TypeMemory ClassAddress Range
0x00data / idataDATA / IDATAI:0x00-I:0xFF
0x01xdataXDATAX:0x0000-X:0xFFFF
0x02-0x7FfarHDATAX:0x010000-X:0x7E0000
0x80unused
0x81-0xFDfar constHCONSTC:0x800000-C:0xFC0000 (far const is mapped into the banked memory areas)
0xFEpdataXDATAone 256-byte page in XDATA memory
0xFFcodeCODE / CONSTC:0x0000-C:0xFFFF

The R3 values 0x00, 0x01, 0xFE and 0xFF are already handled within the run-time library. Only the values 0x02 - 0xFE are passed to the XPTR access routines described above. The AX51 macro assembler provides the MBYTE operator that calculates the R3 value that needs to be passed to the XPTR access function. Below is an AX51 Assembler example for using XPTR access functions:

MOV  R1,#LOW   (variable)   ; gives LSB address byte of variable
MOV  R2,#HIGH  (variable)   ; gives MSB address byte of variable
MOV  R3,#MBYTE (variable)   ; gives memory type byte of variable
CALL ?C?CLDXPTR             ; load BYTE variable into A