Mikroelektronika MIKROE-350 Data Sheet
ACCESSING INDIVIDUAL BITS
The mikroBasic PRO for AVR allows you to access individual bits of 8-bit variables.
It also supports sbit and bit data types
It also supports sbit and bit data types
Accessing Individual Bits Of Variables
To access the individual bits, simply use the direct member selector (.) with a vari-
able, followed by one of identifiers B0, B1, … , B7, or 0, 1, … 7, with 7 being the
most significant bit :
able, followed by one of identifiers B0, B1, … , B7, or 0, 1, … 7, with 7 being the
most significant bit :
// Clear bit 0 on PORTA
PORTA.B0 = 0
// Clear bit 5 on PORTB
PORTB.5 = 0
There is no need of any special declarations. This kind of selective access is an
intrinsic feature of mikroBasic 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.
intrinsic feature of mikroBasic 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.
sbit type
The mikroBasic PRO for AVR compiler has sbit data type which provides access to
bit-addressable SFRs. You can access them in several ways:
bit-addressable SFRs. You can access them in several ways:
dim LEDA as sbit at PORTA.B0
dim Name as sbit at sfr-name.B<bit-position>
dim Name as sbit at sfr-name.B<bit-position>
dim LEDB
as sbit at PORTB.0
dim Name
as sbit at sfr-name.<bit-position>
90
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Specifics
mikroBasic PRO for AVR
CHAPTER 3