sbit

With typical 8051 applications, it is often necessary to access individual bits within an SFR. The C51 compiler makes this possible with the sbit data type. The sbit data type allows you to access bit-addressable SFRs. For example:
sbit EA = 0xAF;

This declaration defines EA  to be the SFR bit at address 0xAF. On the 8051, this is the enable all bit in the interrupt enable register.

NOTE
Not all SFRs are bit-addressable. Only those SFRs whose address is evenly divisible by 8 are bit-addressable. These SFR’s lower nibble will be either 0 or 8; for example, SFRs at 0xA8 and 0xD0 are bit-addressable, whereas SFRs at 0xC7 and 0xEB are not. SFR bit addresses are easy to calculate. Add the bit position to the SFR byte address to get the SFR bit address. So, to access bit 6 in the SFR at 0xC8, the SFR bit address would be 0xCE (0xC8 + 6).

Any symbolic name can be used in an sbit declaration. The expression to the right of the equal sign (=) specifies an absolute bit address for the symbolic name. There are three variants for specifying the address.

    Variant 1: sfr_name ^ int_constant

This variant uses a previously-declared sfr (sfr_name) as the base address for the sbit. The address of the existing SFR must be evenly divisible by 8. The expression following the carat symbol (^) specifies the position of the bit to access with this declaration. The bit position must be a number in the range 0 to 7. For example:
sfr PSW = 0xD0;
sfr IE = 0xA8;

sbit OV = PSW ^ 2;
sbit CY = PSW ^ 7;

sbit EA = IE ^ 7;

    Variant 2: int_constant ^ int_constant

This variant uses an integer constant as the base address for the sbit.  The base address value must be evenly divisible by 8. The expression following the carat symbol (^) specifies the position of the bit to access with this declaration. The bit position must be a number in the range 0 to 7. For example:
sbit OV = 0xD0 ^ 2;
sbit CY = 0xD0 ^ 7;

sbit EA = 0xA8 ^ 7;

    Variant 3: int_constant

This variant uses an absolute bit address for the sbit. For example:
sbit OV = 0xD2;
sbit CY = 0xD7;

sbit EA = 0xAF;

NOTES
Special function bits represent an independent declaration class that may not be interchanged with other bit declarations or bit fields.

The sbit data type declaration may be used to access individual bits of variables declared with the bdata memory type specifier. See the section entitled “Bit-Addressable Objects” in this chapter.