Crossware

Table of Contents        Previous topic       Next topic       

C COMPILER->Accessing the 8051 Internal Registers->SFR Bits

The _sfrbit keyword is used to declare an identifier which accesses a 1 bit wide bit addressable location.  (The location need not be in sfr data space  see Bit Addressable Objects for further information on how to use _sfrbit with non-sfr data space objects.)

The format for the declaration is:

_sfrbit <identifier name> = <bit address>;

or:

_sfrbit <identifier name> = <bit addressable identifier>^<bit offset>;

For example:

_sfrbit Pin = 0X84;

declares Pin to be bit address 84 hex.

When you assign a value to Pin the value is written to bit address 84.

When you assign Pin to another variable, or use Pin in an expression, the value is read from bit address 84.

When you OR Pin with a variable (or a constant), the value is read from bit address 84, ORed with the variable and written back to bit address 84.

Another example:

_sfr Port = 0X90;
_sfrbit Pin3 = Port^3;

declares Pin3 to be bit four of the 8 bit wide location address by identifier Port.  In this case it computes to bit address 93 hex.