C166 User's GuideC166 Introduction Compiling Programs Language Extensions Keywords Memory Models Tiny Model Small Model Medium Model Compact Model Large Model HCompact Model HLarge Model XLarge Model Memory Types near far bdata ebdata idata sdata huge xhuge Memory Type Comparison Pointers with Memory Types Implicit Memory Types Type Qualifiers const volatile Data Types Special Function Registers sfr Types sbit Types bit Types Bit-Addressable Objects Function Declarations Return Values Register Bank Register Mask Interrupt Functions Fast Interrupts Cached Vectors Fast Register Banks Inline Functions Real-Time Function Tasks Inline Assembly Traditional Inline Assembly Extended Inline Assembly Operands Operators Register Use Use in Macro Definitions Preprocessor Advanced Programming Error Messages Library Reference Appendix
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:
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;
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;
of your data.