Keil Logo

sbit Types

The sbit keyword allows you to define objects that access individual bits of bit-addressable SFRs and bit-addressable objects. For example:

sbit IEN = PSW ^ 11;

defines IEN as an SFR bit at bit 11 of the PSW. On the C16x/ST10 microcontroller, this is the global interrupt enable bit in the PSW register.

Any symbolic name may be used in an sbit declaration. The expression to the right of the equal sign ('=') specifies an absolute bit address for the symbolic name. Two variations of this definition are possible:

Variant 1

sbit name = sfr-name ^ bit-position;

The previously declared SFR (sfr-name) is the base address for the sbit. The bit-position (which must be a number from 0-15) follows the carat symbol ('^') and specifies the bit position to access. For example:

sfr  PSW   = 0xFF10;
sbit USR0  = PSW ^ 6;
sfr  ADCON = 0xFFA0;
sbit ADBSY = ADCON ^ 8;

Variant 2

sbit name = sfr-address ^ bit-position;

An integer constant (sfr-address) specifies the base address for the sbit. The bit-position (which must be a number from 0-15) follows the carat symbol ('^') and specifies the bit position to access. For example:

sbit ADBSY = 0xFFA0 ^ 8;
sbit USR0  = 0xFF10 ^ 6;

Note

  • Special function bits represent an independent declaration class that is not interchangeable 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. Refer to Bit-Addressable Objects for more information.
  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.