Mikroelektronika MIKROE-738 Datenbogen
mikroC PRO for PIC32
MikroElektronika
139
Note: If aiming at portability, avoid this style of accessing individual bits, use the bit fields instead.
See Predefined Globals and Constants for more information on register/bit names.
sbit type
The mikroC PRO for PIC32 compiler has
sbit
data type which provides access to registers, SFRs, variables, etc.
You can declare a
sbit
variable in a unit in such way that it points to a specific bit in SFR register:
extern sfr sbit Abit; // Abit is precisely defined in some external file, for example in
the main program unit
In the main program you have to specify to which register this sbit points to, for example:
sbit Abit at PORTB.B0; // this is where Abit is fully defined
...
void main() {
...
}
In this way the variable
Abit
will actually point to PORTB.0. Please note that we used the keyword
sfr
for declaration
of
Abit
, because we are pointing it to PORTB which is defined as a
sfr
variable.
Note: Declaring a
sbit
variable is not possible via
F0, F1, … F31
identifiers.
In case we want to declare a bit over a variable which is not defined as
sfr
, then the keyword
sfr
is not necessary,
for example:
extern sbit AnotherBit; // AnotherBit is precisely defined in some external file, for
example in the main program unit
char MyVar;
sbit AnotherBit at MyVar.B0; // this is where AnotherBit is fully defined
...
void main() {
...
}