Keil Logo


Information in this article applies to:

  • C51 Version 5.50


I know that code banking is built-in, but my question concerns XDATA banking. I have a 128K SRAM that is configured on the board as 4x32K ram areas. Is there any type of intrisic support for banked XDATA? if not, do you have any ideas for how (or if) I could build it in?


There is no built in support for XDATA banking, however, it is easy to implement this yourself. The best way is to use XBYTE to access XDATA as an "array".

Example 1: Accessing a 32k "array" in two XDATA banks:

// access XDATA in bank 0
P1.0 = 0;
XBYTE[0x36FF] = 4;

// access XDATA in bank 1
P1.0 = 1;
XBYTE[0x2143] = 6;

Example 2: Accessing 16M of RAM split over 256 XDATA banks:

void write_byte(unsigned long loc, unsigned char byte)
P1 = (loc >> 16) & 0x00FF;   // Write upper address byte
XBYTE[loc & 0x0000FFFF] = byte;   // Write data byte

unsigned char read_byte(unsigned long loc)
P1 = (loc >> 16) & 0x00FF;   // Write upper address byte
return (XBYTE[loc & 0x0000FFFF]);   // Read data byte

Note the use of P1 to select the XDATA bank. You may use fewer bits from the port if you don't need 16 MegaBytes of XDATA.


  • Refer to XBYTE in the Cx51 User's Guide.

Last Reviewed: Friday, July 15, 2005

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.