Standard Variables
Variables are locations in RAM (Random Access Memory) where temporary data is stored in a program, and are created using the Dim directive. Because RAM space on some 8-bit microcontrollers is somewhat limited, choosing the right size variable for a specific task is important. Variables may be Bit, Byte, Pin, Word, Long, Dword, SByte, SWord, SDword, Float, or String.
Space for each variable is automatically allocated in the microcontroller's RAM area. The format for creating a variable is as follows: -
Dim Name as Type
Name is any valid identifier, (excluding keywords). Type is Bit, Pin, Byte, Word, Long, Dword, SByte, SWord, Sdword, Float, or Double. Some examples of creating variables are: -
Dim tCat as Bit ' Create a single bit variable (0 or 1)
Dim bDog as Byte ' Create an 8-bit unsigned variable (0 to 255)
Dim MyPin as Pin ' Create a variable that will hold a Port.Pin mask
Dim wRat as Word ' Create a 16-bit unsigned variable (0 to 65535)
Dim lRat as Long ' Create a 24-bit unsigned variable (0 to 16777215)
Dim dRat as Dword ' Create a 32-bit unsigned variable (0 to 4294967295)
Dim fBoat as Float ' Create a 32-bit Floating Point variable
Dim sbDog as SByte ' Create an 8-bit signed variable (-128 to +127)
Dim swRat as SWord ' Create a 16-bit signed variable (-32768 to +32767)
Dim sdRat as SDword ' Create a 32-bit signed variable (-2147483648 to
' +2147483647)
The number of variables available depends on the amount of RAM on a particular device and the size of the variables within the BASIC program. The compiler will reserve RAM for its own use and may also create additional temporary (System) variables for use when calculating expressions or more complex command structures. Especially if floating point calculations are carried out.
