Variable Types

The 12 supported variable types are:

Boolean

A Boolean is a single bit variable.

Range: 0 to 1


Byte

A Byte is a signed 8 bit variable.

Range: -128 to 127


uByte

A uByte is an unsigned 8 bit variable.

Range: 0 to 255


Integer

An Integer is a signed 16 bit variable.

Range: -32768 to 32767


uInteger

A uIntger is an unsigned 16 bit variable.

Range: 0 to 65535


Short

A Short is a signed 24 bit variable.

Range: -8388608 to 8388607


uShort

A uShort is an unsigned 24 bit variable.

Range: 0 to 16777215


Long

A Long is a signed 32 bit variable.

Range: -2147483648 to 2147483647


uLong

A uLong is an unsigned 32 bit variable.

Range: 0 to 4294967295


Fixed

A Fixed is a unsigned 32 bit fixed point variable.  With a 16 bit integer portion, and a 16 bit fractional portion.

Range: 0 to 65535.9999847412109375
Resolution:
0.0000152587890625


Single

A Single is a signed 32 bit floating point variable.

They have been implemented using AN575 modified for the PIC18C series.  Before using Single variables the file fp32.bas must be included.  For advanced floating point operations fp32ext.bas must be included.  See the floating point library reference. 

The exception flags and option flags are defined as follows:

IOV

Integer overflow flag

SAT

Saturate enable flag

FOV

Floating point overflow flag

FUN

Floating point underflow flag

FDZ

Floating point Divide by Zero flag

RND

Rounding enable bit

DOM

Domain error

Example:

Include <18c452.bas>   ' include the processor definition file

Include <fp32.bas>     ' include floating point variables and libraries
 

Sub main()

  Dim a As Single, b As Single  ' Define variables
 
  a=PORTB    ' assign the value of PORTB to a
  b=PORTD    ' assign the value of PORTD to b
             ' (type conversion is automatic)
 
  RND=0      ' Disable rounding
  SAT=0      ' Disable saturation
 
  a=a/b      ' floating point divide
  If FDZ=1 Then
     ' Divide by Zero Error
  End If
End Sub

 

 


String

Strings are variables that point to blocks of character data.  Defining a string is the same as defining an array.

Dim stringName(size) As String

All strings are terminated with a 0 character, therefore the size must be at least one greater than the number of characters you wish to hold.  Most string operations are supported by built-in library calls, however there is native support for constant assignments.

Assigning a constant to a string:

 

Dim s(15) As String  ' Create a 15 character String
s="Test String"

Strings are also different when being passed to a function or procedure in that they are passed by reference.  Therefore no size information is needed in the parameter list.

Sub main()
  Dim s(15) As String
 
  s="Test"
  call str2USART(s)     ' A string must be loaded into a variable
                        ' before it can be passed as a parameter
End Sub
 
' Send a string out the USART
Sub str2USART(s As String)

 
  FSR0=Addr(s)
  While INDF0<>0
    While TXIF=0: Wend ' Wait on the Transmit buffer to empty
    TXREG=POSTINC0     ' Transmit this character and bump the pointer
                       ' to the next character
  Wend
End Sub

Also See: