Positron Compiler Documentation

SFR bit access using the preprocessor’s built-in meta-macros

Source: Positron8 Compiler User Manual, PDF page 480

The SFR bit names are extremely useful within the BASIC program because they circumvent any differences in the device's makeup. For example, in order to access a device’s Carry flag, use: STATUSbits_C

All the bit names follow the same rule, where the SFR name is first, followed by the text "bits_", followed by the bit name. Below are a few examples:

T1CONbits_TCS T1CONbits_TSYNC T1CONbits_TGATE T1CONbits_TSIDL T1CONbits_TON T1CONbits_TCKPS0 T1CONbits_TCKPS1

To see all the SFR bit meta-macros available to a device, open the device’s .def file and there is a compete list of them for all the SFRs and bit names attached to them. The .def files can be found within the compiler’s folder, inside the Defs folder.

$else

This toggles the logical value of the current conditional block. What follows is evaluated if and only if the preceding input was commented out.

$endif

This ends a conditional block started by the $if directive.

$elseif expression This directive can be used to avoid nested $if conditions. $if..$elseif..$endif is equivalent to

$if..$else $if ..$endif $endif.

The $if, $else and $elseif directives serve to specify some condition to be met in order for the portion of code they surround to be compiled. The condition that follows $if or $elseif can only evaluate constant expressions, including macro expressions. For example:-

$if TableSize > 200
  $undef TableSize
  $define TableSize 200
$elseif TableSize < 50
  $undef TableSize
  $define TableSize 50
$else
  $undef TableSize
  $define TableSize 100
$endif
Dim Table[TableSize] as Byte

Notice how the whole structure of $if, $elseif and $else chained directives ends with $endif.

The behaviour of $ifdef and $ifndef can also be achieved by using the special built-in user directive _defined and ! _defined respectively, in any $if or $elseif condition. These allow more flexibility than $ifdef and $ifndef. For example:-

$if _defined (MyDefine) and _defined (AnotherDefine)
  { BASIC Code Here }
$endif

The argument for the _defined user directive must be surrounded by parenthesis. The preceding character “!” means “not”.

$SendError "Error Text" This directive causes an error message to be sent from the compiler, and stops the compile.

$SendError "Error Message Here"

$SendWarning "Warning Text" This directive causes a warning message to be sent from the compiler.

$SendWarning "Warning Message Here"

$SendHint "Hint Text" This directive causes a hint (reminder) message to be sent from the compiler.

$SendHint "Hint Message Here"

Proton8 IDE Overview