Keil Logo

C51: ARE 32-BIT SFRS SUPPORTED?


Information in this article applies to:

  • C51 Version 5.50a
  • C51 Version 6.01

QUESTION

I'm using a custom 8051 that has a floating-point coprocessor. I need to access 32-bit numbers stored in the SFR space of the 8051. Does the C51 compiler do this?

ANSWER

There is no support in the C51 compiler for 32-bit objects stored in the SFR space of the 8051. There is support for 8-bit objects (use SFR) and 16-bit objects (use SFR16).

To access a 32-bit object, you will have to use either 4 SFR accesses or 2 SFR16 accesses as shown below:

sfr OBJ_BYTE_1 = 0xF1;
sfr OBJ_BYTE_2 = 0xF2;
sfr OBJ_BYTE_3 = 0xF3;
sfr OBJ_BYTE_4 = 0xF4;

void write_obj (unsigned long value)
{
OBJ_BYTE_1 = value & 0xFF;
OBJ_BYTE_2 = (value >> 8) & 0xFF;
OBJ_BYTE_3 = (value >> 16) & 0xFF;
OBJ_BYTE_4 = (value >> 24) & 0xFF;
}

or

sfr16 OBJ_WORD_1 = 0xF1;
sfr16 OBJ_WORD_2 = 0xF3;

void write_obj (unsigned long value)
{
OBJ_WORD_1 = value & 0xFFFF;
OBJ_WORD_2 = (value >> 16) & 0xFFFF;
}

MORE INFORMATION

SEE ALSO

Last Reviewed: Tuesday, March 27, 2007


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.