Keil Logo

C51: ACCESS TO PAGED SFR REGISTERS


Information in this article applies to:

  • C51 Compiler any Version

QUESTION

I am using the Infineon XC800 device which has several SFR pages. Is there a built-in method in the C51 Compiler to access the various SFR pages?

ANSWER

There is no special compiler extension for accessing paged SFR registers. The SFR pages can be easily accessed using the standard SFR definition.

The following example presents two possible ways to access the paged SFR registers available in this device. We recommend using Solution 1: via page select macros since it avoids additional save/restore instruction and gives the most efficient code.

sfr PORT_PAGE=0xB2;
#define _p0  PORT_PAGE=0  // PORT_PAGE postfix
#define _p1  PORT_PAGE=1  // PORT_PAGE postfix
#define _p2  PORT_PAGE=2  // PORT_PAGE postfix


sfr P0_DATA      =0x80;   // standard SFR
sfr P0_PUDSEL_p1 =0x80;   // sfr 0x80 when PORT_PAGE=1
sfr P0_ALTSEL1_p2=0x80;   // sfr 0x80 when PORT_PAGE=2


sfr ADC_PAGE=0xD1;
#define _a0  ADC_PAGE=1   // ADC_PAGE postfix
#define _a1  ADC_PAGE=1   // ADC_PAGE postfix
#define _a2  ADC_PAGE=2   // ADC_PAGE postfix


sfr GLOBCTR  =0xCA;
sfr CHCTR0_a1=0xCA;
sfr RESR0L_a2=0xCA;

// Solution 1: via page select macros
#define SST0  0x80         // Save SFR page to ST0
#define RST0  0xC0         // Restore SFR page from ST0
#define SST1  0x90         // Save SFR page to ST1
#define RST1  0xD0         // Restore SFR page from ST1
#define SST2  0xA0         // Save SFR page to ST2
#define RST2  0xE0         // Restore SFR page from ST2
#define SST3  0xB0         // Save SFR page to ST3
#define RST3  0xF0         // Restore SFR page from ST3

#define SFR_PAGE(pg,op)   pg+op


// Solution 2: via read/write macros
#define PG_SAVE0     0x20         // Save SFR page to ST0
#define PG_RESTORE0  0x30         // Restore SFR page from ST0
#define __sget(page,sfr,val)   PORT_PAGE=PG_SAVE0+page; val=sfr; PORT_PAGE=PG_RESTORE0;
#define __sset(page,sfr,val)   PORT_PAGE=PG_SAVE0+page; sfr=val; PORT_PAGE=PG_RESTORE0;


#define rdP0_PUDSEL(val)  __sget(1, P0_PUDSEL_p1, val);
#define wrP0_PUDSEL(val)  __sset(1, P0_PUDSEL_p1, val);


unsigned char v;


void main (void)  {

// Solution 1: using explicit control
  SFR_PAGE (_p1, SST0);    // save page to ST0
  v = P0_PUDSEL_p1;
  P0_PUDSEL_p1 = 0x55;
  SFR_PAGE (_p1, RST0);    // restore from ST0

  SFR_PAGE (_p1, SST1);
  v = P0_PUDSEL_p1;
  P0_PUDSEL_p1 = 0x55;
  SFR_PAGE (_p0, RST1);

  SFR_PAGE (_a1, 0);       // select ADC_PAGE 1
  CHCTR0_a1=2;
  SFR_PAGE (_a2, 0);       // select ADC_PAGE 2
  RESR0L_a2=3;
  SFR_PAGE (_a0, 0);       // select ADC_PAGE 0


// Solution 2: using read/write macros
  rdP0_PUDSEL (v);       // read  P0_PUDSEL
  wrP0_PUDSEL (0x55);    // write P0_PUDSEL

}

MORE INFORMATION

Last Reviewed: Friday, July 15, 2005


Did this article provide the answer you needed?
 
Yes
No
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.