Keil Logo

C51: ERRORS USING SBITS AND SFRS


Information in this article applies to:

  • C51 All Versions

QUESTION

I've created the following program.

void main (void)
{
sfr P1 = 0x90;

while (1)
  {
  P1 ^= 0xFF;
  }
}

When I compile it, I receive the following error messages:

*** ERROR C141 IN LINE 3 OF .\MAIN.C: syntax error near 'sfr'
*** ERROR C202 IN LINE 3 OF .\MAIN.C: 'P1': undefined identifier

What's wrong?

ANSWER

SBIT and SFR objects may not be declared inside a function definition. They must be declared outside of a function. The following code compiles with no errors or warnings.

sfr P1 = 0x90;

void main (void)
{
while (1)
  {
  P1 ^= 0xFF;
  }
}

MORE INFORMATION

  • Refer to sfr in the Cx51 User's Guide.
  • Refer to sbit in the Cx51 User's Guide.

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.