Positron Compiler Documentation

ClearBit

Source: Positron16 Compiler User Manual, PDF page 330

Syntax

ClearBit Variable, Index

Overview

Clear a bit of a variable or register using a variable index to the bit of interest.

Parameters

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

Example

' Clear then Set each bit of variable ExVar
  Device = 24FJ64GA002
                                   ' Select the device to compile for
  Declare Xtal = 16
  Declare Hserial_Baud = 9600
                                   ' USART1 Baud rate
  Declare Hrsout1_Pin = PORTB.14  ' Select the pin used for TX with USART1
  Dim MyByte as Byte
  Dim Index as Byte
  RPOR7 = 3                     ' Make PPS Pin RP14 U1TX
  MyByte = %11111111
  Do
                                   ' Create an infinite loop
     For Index = 0 to 7
                                   ' Create a loop for 8 bits
       ClearBit MyByte, Index
                                   ' Clear each bit of MyByte
       Hrsout Bin8 MyByte, 13
                                   ' Display the binary result
       DelayMs 100
                                   ' Slow things down to see what's happening
     Next
                                   ' Close the loop
     For Index = 7 to 0 Step -1
                                   ' Create a loop for 8 bits
       SetBit MyByte, Index
                                   ' Set each bit of MyByte
       Hrsout Bin8 MyByte, 13
                                   ' Display the binary result
       DelayMs 100
                                   ' Slow things down to see what's happening
     Next
                                   ' Close the loop
  Loop
                                   ' Do it forever

Notes.

There are many ways to clear a bit within a variable, however, each method requires a certain amount of manipulation, either with rotates, or alternatively, the use of indirect addressing. Each method has its merits, but requires a certain amount of knowledge to accomplish the task correctly. The ClearBit command makes this task extremely simple using a register rotate method, however, this is not necessarily the quickest method, or the smallest, but it is the easiest. For speed and size optimisation, there is no shortcut to experience.

To clear a known constant bit of a variable or register, then access the bit directly using PORT.n.

PORTA.1 = 0

or

Var1.4 = 0

If a Port is targeted by ClearBit, the TRIS register is not affected.

See also : GetBit, LoadBit, SetBit.