现在,流行的51单片机大多把on-chip expanded RAM(以下简称XRAM)作为基本配置,容量有些差别。
厂商在给出芯片特性时,往往把XRAM和标准52芯片的256字节内部RAM加在一起统称为on-chip RAM容量,有的是512(256+256),有的是1024(256+768),有的是1280(256+1024)。
最关键的是对这些XRAM的Enable/Disable上,不同厂商的控制有些差别:所涉及的SFR地址、在SFR中和XRAM相关的位所在位置和上电复位后XRAM的状态。
----------------------------------------------------------------
SyncMOS Technologies Inc.
SM5964

System Control Register (SCONF, $BF)

The bit 1 (OME) of special function register $BF (SCONF) can enable or disable this expanded 768 byte RAM. The default setting of OME bit is 1 (enable).

sfr        SCONF = 0xBF;
        SCONF = 0x02;        //允许访问SM5964的片上XRAM

----------------------------------------------------------------
Silicon Storage Technology, Inc.
SST89E564RD

Auxiliary Register (AUXR)
EXTRAM(AUXR.1):
0 - Internal Expanded RAM access.
1 - External data memory access.

sfr        AUXR = 0x8E;
        AUXR = 0x00;        //允许访问SST89E564RD的片上XRAM

----------------------------------------------------------------
Philips Semiconductors
P89C51RD2

AUXR Address = 8EH
EXTRAM(AUXR.1) Internal/External RAM access using MOVX @Ri/@DPTR
EXTRAM Operating Mode:
0 - Internal ERAM access using MOVX @Ri/@DPTR
1 - External data memory access.

sfr        AUXR = 0x8E;
        AUXR = 0x00;        //允许访问P89C51RD2的片上XRAM

----------------------------------------------------------------
Winbond Electronics Corp.
W78E516

The AUX-RAM is disable after a reset. Setting the bit 4 in CHPCON register will enable the access to AUX-RAM. When AUX-RAM is enabled the
instructions of "MOVX @Ri" will always access to on-chip AUX-RAM. When executing from internal program memory, an access to AUX-RAM will not affect the Ports P0, P2, WR and RD.

sfr        CHPENR = 0xF6
sfr        CHPCON = 0xBF

CHPENR = 0x87;
        CHPENR = 0x59;
        CHPCON |= 0x10;        //允许访问W78E516的片上XRAM
        CHPENR = 0x00;

----------------------------------------------------------------
由此看来,要使用片上XRAM,必须仔细阅读芯片datasheet中XRAM的相关内容,并小心控制。

个人习惯:1、不使用芯片本身的默认状态,不管是允许或者禁止,都显式地用指令控制相关的特殊功能寄存器。
2、为了更好地使用这些XRAM,在给外设进行编址时,避开0x0000~0x02FF空间(比如从0x1000开始)。

05-06 17:02