Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
141
sbit type
The mikroBasic PRO for dsPIC30/33 and PIC24 compiler has 
sbit
 data type which provides access to registers, 
SFRs, variables, etc. 
You can declare a 
sbit
 varible in a unit in such way that it points to a specific bit in SFR register:
module MyModule
   
dim  Abit  as  sbit  sfr  external  ‘  Abit  is  precisely  defined  in  some  external  file,  for 
example in the main program unit
...
implements
....
end.
In the main program you have to specify to which register this sbit points to, for example:
program MyProgram
...
dim Abit as sbit at PORTB.0 ‘ this is where Abit is fully defined
...
main:
...
end.
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. 
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: 
module Mymodule
   
dim AnotherBit as sbit external ‘ Abit is precisely defined in some external file, for 
example in the main program unit
...
implements
...
end.
program MyProgram
...
dim MyVar as byte
dim Abit as sbit at MyVar.0 ‘ this is where Abit is fully defined
...
main:
...
end.