Keil™, An ARM® Company

Cx51 User's Guide

far

The far memory type may be used for variables and constants. This memory is accessed using 24-bit addresses and may be on-chip or external.

  • For variables, far memory is limited to 16M. Objects are limited to 64K and may not cross a 64K boundary. Variables declared far are located in the HDATA memory class.
  • For constants (ROM variables), far memory is limited to 16M. Objects are limited to 64K and may not cross a 64K boundary. Constant variables declared far are located in the HCONST group.

Declare far objects as follows:

unsigned char far far_variable;

unsigned char const far far_const_variable;

The actual address range that can be addressed with the far memory type depends on the chip architecture or the banking configuration file. The far memory is addressed using 3-byte generic pointers. The mapping of the Memory Type Byte (uppermost byte) differs for each architecture and is shown below:

  • NXP 80C51MX: the complete 16MB address space can be addressed without restrictions.

    Memory Type ByteAddressed Memory Region
    0x00XDATA, HDATA (0x000000 - 0x00FFFF)
    0x01 - 0x7EHDATA (0x010000 - 0x7EFFFF)
    0x7FDATA, IDATA, EDATA (0x7F0000 - 0x7FFFFF)
    0x80CODE, ECODE (0x800000 - C:0x80FFFF)
    0x81 - 0xFFECODE (0x810000 - C:0xFFFFFF)

  • Dallas Contiguous Mode: far and const far are limited to 8MB-64KB address space.

    Memory Type ByteAddressed Memory Region
    0x00DATA/IDATA/BDATA
    0x01 - 0x7FXDATA Memory (X:0 - X:0x7EFFFF)
    0x80Unused
    0x81 - 0xFFCODE Memory (C:0 - C:0x7EFFFF)

  • XBANKING.A51 Configuration File: far and const far are handled by user provided routines. The following table lists the default mapping of the file ..\C51\LIB\XBANKING.A51.

    The examples in the folder ..\C51\Examples\FarMemory (i.e. for ADuC812) may have a different mapping. The actual mapping is described in each XBANKING.A51 file.

    Memory Type ByteAddressed Memory Region
    0x00DATA/IDATA/BDATA
    0x01classic 8051 XDATA Memory (X:0 - X:0xFFFF)
    0x02 - 0x7Fextended HDATA Memory (X:0x10000 - X:0x7EFFFF)
    0x80Unused
    0x81 - 0xFDextended HCONST Memory (C:0x800000 - C:0xFC0000).
    0xFEPDATA Memory (one 256-byte page in XDATA)
    0xFFclassic 8051 CODE Memory (C:0 - C:0xFFFF)

  • L51_BANK.A51 Configuration File: far and const far can be handled with code banking routines.

    Memory Type ByteAddressed Memory Region
    0x00DATA/IDATA/BDATA
    0x01classic 8051 XDATA Memory (X:0 - X:0xFFFF)
    0x02 - 0x40extended HDATA Memory (X:0x10000 - X:0x3FFFFF)
    0x41 - 0x80Unused
    0x81 - 0xC1extended HCONST Memory mapped to code banks (B0:0x0 - B31:0xFFFF).
    0xC2 - 0xFDUnused
    0xFEPDATA Memory (one 256-byte page in XDATA)
    0xFFclassic 8051 CODE Memory (C:0 - C:0xFFFF)

     

Note

  • Pointer arithmetic for far objects is performed using 16-bit math operations by default. The upper byte of the complete 24-bit address is unchanged even if the operation's result is larger than 0xFFFF. You may coerce the compiler to use 24-bit math by using long types or casting constants to long types in pointer manipulations. For example:
    char far *fp;
    unsigned long i;
    unsigned long ttl;
    
    for (ttl=0, i=0; i<0x20000; i++)
      {
      ttl += fp[i];
      }