Datasheet
ACCESSING INDIVIDUAL BITS
The mikroC PRO for AVR allows you to access individual bits of 8-bit variables. It
also supports sbit and bit data types
Accessing Individual Bits Of Variables
If you are familiar with a particular MCU, you can access bits by name:
// Clear bit 0 on PORTA
PORTA0_bit = 0;
Also, you can simply use the direct member selector (.) with a variable, followed by
one of identifiers B0, B1, … , B7 with B7 being the most significant bit:
// Clear bit 0 on PORTA
PORTA.B0 = 0;
There is no need of any special declarations. This kind of selective access is an
intrinsic feature of mikroC PRO for AVR and can be used anywhere in the code.
Identifiers B0–B7 are not case sensitive and have a specific namespace. You may
override them with your own members
B0–B7 within any given structure.
See Predefined Globals and Constants for more information on register/bit names.
Note: If aiming at portability, avoid this style of accessing individual bits, use the bit
fields instead.
sbit type
The mikroC PRO for AVR compiler has sbit data type which provides access to
bit-addressable SFRs. For example:
sbit LEDA at PORTA.B0;
sbit name at sfr-name.B<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-7) follows the dot symbol ('.') and speci-
fies the bit position to access. For example:
sbit OV at SREG.B2;
sbit CY at SREG.B7;
100
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Specifics
mikroC PRO for AVR
CHAPTER 3