Positron Compiler Documentation

Symbols

Positron8 · Revision 4.0.6.5 · PDF page 38

The Symbol directive provides yet another method for aliasing variables and constants. Symbol cannot be used to create a variable. Constants declared using Symbol do not use any RAM within the microcontroller and are only accessed at compile time, not while the program is running.

Symbol cCat = 123
Symbol cTiger = Cat                ' cTiger now holds the value of cCat
Symbol cMouse = 1                  ' Same as Dim cMouse as 1
Symbol cTigOuse = (cTiger + cMouse) ' Add cTiger to cMouse to make Tigouse

Floating point constants may also be created using Symbol by simply adding a decimal point to a value.

Symbol cPI = 3.14   ' Create a floating point constant named cPI
Symbol cFlNum = 5.0  ' Create a floating point constant holding the value 5

Floating point constants can also be created using expressions.

' Create a floating point constant holding the result of the expression
Symbol cQuanta = (5.0 / 1024)

If a variable or register's name is used in a constant expression then the variable's or register's address will be substituted, not the value held in the variable or register: -

Symbol cMyConst = (PORTA + 1)  ' cMyConst will hold the value 6 (5+1)

Symbol is also useful for aliasing Ports and Registers: -

Symbol LED = PORTA.1      ' LED now references bit-1 of PORTA
Symbol T0IF = INTCON.2   ' T0IF now references bit-2 of INTCON register

The equal sign between the constant's name and the alias value is optional: -

Symbol LED PORTA.1        ' Same as Symbol LED=PORTA.1

Notice the lowercase ‘c’ before a constant’s name? This is not mandatory, but it helps to show that the name is a constant value when scanning a program’s listing.

Even though Symbol can be used for aliasing, it is my opinion that Dim is a better option for aliases. This keeps program listings easier to scan and read.

View original PDF page 38Open page in PDFOriginal PDF page 38