Positron Compiler Documentation

GetBit

Source: Positron8 Compiler User Manual, PDF page 329

Syntax

Variable = GetBit Variable1, Index

Overview

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

Parameters

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

Example

' 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.