Positron Compiler Documentation

GetBit

Positron8 · Revision 4.0.6.5 · PDF page 329

Variable = GetBit Variable1, Index

Examine a bit of a variable, or SFR (Special Function Register).

Variable1 is a user defined variable. Index is a constant, variable, or expression that points to the bit within Variable1 that requires examining.

' Examine and display each bit of variable ExVar
  Device = 18F26K40          ' Compile for an 18F device
  Declare Xtal = 20          ' Tell the compiler the device is operating at 20MHz
  Declare Hserial_Baud = 9600  ' Choose the Baud rate for HRsoutLn

  Dim ExVar as Byte
  Dim Index as Byte
  Dim BitVal as Byte

  ExVar = 0b10110111

  Do
     HRsoutLn Bin8 ExVar             ' Display the original variable
     For Index = 7 to 0 Step -1       ' Create a loop for 8 bits
       BitVal = GetBit ExVar, Index   ' Examine each bit of ExVar
       HRsout Dec1 BitVal             ' Display the binary result
       DelayMs 100                    ' Slow things down to see what's happening
     Next                             ' Close the loop
     HRsout 13                         ' Send a CR to move to the next line
  Loop                                ' Do it forever

See also : ClearBit, LoadBit, SetBit.

View original PDF page 329Open page in PDFOriginal PDF page 329