GCBASIC Command Guide
GCBASIC Command Guide
Legend to highlighting:
Tested and working
Tested and not working
Not tested
Not implemented
Supported chips:
In theory, all 10/12/14/16/18 series PIC chips. See chipdata.csv for a complete list.
Some features may not work on all chips – if you find that this is the case, please do
not hesitate to email [email protected] with the name of the chip and the
feature that is causing difficulty.
Commands:
Note: All standard PIC assembly mnemonics can be inserted directly in to the
GCBASIC program – anything not recognized by the compiler will be passed straight
through to the assembly.
Command Explanation
Flow Control
IF condition THEN Execute commands between IF and END IF, if condition is
… true.
END IF
IF condition THEN Short form of IF. Does not require END IF. Command
command must be on same line as IF.
GOTO label Jump to label
label: Defines a label
GOSUB label Call label as a subroutine
RETURN Return from a GOSUB
SubName [(vars)][#NR] Call up sub SubName, and pass vars to it. If vars are
specified, then brackets must be included. #NR stands for
No Return, and will stop the sub from returning values of
variables.
SUB Subname [(vars)] Used to mark the start of a subroutine
EXIT SUB Exit from a subroutine (Only found in subs)
(interchangeable with EXIT FUNCTION)
END SUB Marks the end of a subroutine
(interchangeable with END FUNCTION)
EXIT FUNCTION Exit from a function (Only found in functions)
(interchangeable with EXIT SUB)
FUNCTION Same as for sub, except a value can be returned
functionname [(vars)] automatically ie:
… Var = FunctionName (var2)
END FUNCTION (Note: When defining a function, be sure to return a value.
To do this, set FunctionName to some value/var.)
FOR var = min TO max Loop (max-min) times. Var will start at min and be
STEP step incremented every loop until it is equal to max. During this
…. time, all code up to NEXT will run. Step is number to add
NEXT to var each loop. Step can be a negative.
DO WHILE|UNTIL Repeat code while/until condition is true
condition
…
LOOP
REPEAT count Repeat code count times
…
END REPEAT
SELECT CASE var Run a different section of code, based on the value of var.
CASE value1 The CASE ELSE section runs if none of the others do. Not
… that CASE ELSE is optional.
CASE value2
…
CASE ELSE
…
END SELECT
CALL sub EVERY ticks Call up sub every ticks of the interrupt. Set ticks to 0 to
stop call for a particular sub. (Interrupt must be defined)
Variable
[LET] var1=var2 Set var1 to var2. var2 can be given as a function. LET is
optional, and exists solely for people familiar with other
BASIC dialects. Appending [WORD] to the line will force
the PIC to use 16-bit mode when performing the
calculation.
ROTATE var {LEFT| Rotate var 1 bit left/right
RIGHT} [SIMPLE]
SET var.bit, 0|1 Set bit of var to 0 or 1 (OFF or ON accepted)
DIM ArrayName(size) Initialize an array.
DIM VarName AS type Declare a non-byte variable. Only “word” is a valid type at
present.
Compiler (Commands in main file will override those in includes, and commands in
includes will override those in nested includes)
#include “file.h” Include the subs in file.h into the program
Note: using “” will read the file from the same directory
as the program. If <> are used, the file will be read from
the default include folder.
#define CONST value Create a constant called CONST, and set it to value, or
#define CONST =sum result of sum.
#chip MODEL, MHz Specifies model and speed of PIC
#osc Type Type is HS/LP/etc.
#config settinglist Settinglist is list of config values in .inc file (WDT_OFF,
etc.)
#IFDEF constant If constant != value/value2/etc, then the code between
value[,value2,etc.] value can also be another constant #IFDEF and #ENDIF
… will be removed from the compiled code.
#ENDIF
#SCRIPT Used to make a script which GCBASIC runs. Use for
… creating code that can be run on different PIC chips. See
#ENDSCRIPT the script commands section for more info
#int frequency Set up an interrupt of the given frequency. Used in
conjunction with the CALL EVERY command. Frequency
is Hz (app. Range on 20 MHz: 76-19,000).
#startup subname Used in include files to define a subroutine that must be
called if anything from that file is used.
#RAM ramsize Specifies the amount of RAM present on the PIC chip. Not
#mem ramsize compulsory, but should be used if arrays are in use.
Functions:
Function Explanation
x * y, x / y, x + y, x - y Self explanatory
x AND y Logical AND of x and y. Spaces must be included
x OR y Logical OR of x and y. Spaces must be included
x XOR y Logical XOR of x and y. Spaces must be included
NOT x Inverts x. Space must be included
x & y, x | y, x # y, ! x Short form of AND, OR, XOR, and NOT respectively.
Spaces are optional with the short form.
x=y Returns 0 if not equal, 255 if equal
x <> y Returns 255 if not equal, 0 if equal
x>y Returns 255 if x is more than y, 0 otherwise
x<y Returns 255 if x is less than y, 0 otherwise
x >= y Returns 255 if x is equal to or more than y, otherwise 0.
x <= y Returns 255 if x is less than or equal to y, otherwise 0.
Short Forms:
x += y is equivalent to x = x + y
x -= y is equivalent to x = x - y
Functions must have “var =” before them (minus quotes), where var is the name of the
variable that is to be set.
Order of operations:
()
+, -
AND, OR, XOR, NOT
Conditions
= (equal)
<> or ~ (not equal)
< (less than)
> (greater than)
<= (less than or equal)
>= (greater than or equal)
Conditions are basically sums, with either zero (false) or non-zero (true) results.
Var(), NoVar(), Bit() and NoBit() are functions that are built in to #IFDEF. They will
return true if a variable or bit is declared/not declared in the currently selected PIC
chip.
AllOf and OneOf will return true if all of or one of the listed defines is declared.
Built-in #defines (used for IFs, WAITs, etc.)
Name Value
ON 1
OFF 0
TRUE 255 (or 1 for bit variables)
FALSE 0
NB. Other #defines are set by the built-in include files.
Time Units
Units GCBASIC units
Microseconds us
Microseconds * 10 10us
Milliseconds ms
Milliseconds * 10 10ms
Seconds s
Minutes m
Hours h
Data Types:
Type Size Range
Bit 1 bit 0 to 1
Byte 8 bits 0 to 255
Word 16 bits 0 to 65535
Float 24 bits ?
Assembler/Programmer parameters:
These options can be used after the /A: and /P: switches to control the assembler and
programming software:
Data Tables:
Data tables can be used to store a list of up to 255 numbers in the program memory of
the chip, in a way that allows them to be recalled. The format is as follows:
Chip Configuration:
The following are the default settings used by GCBASIC for chip configuration:
Oscillator = HS, XT or INTOSC (see help for more detail)
MCLR = Off
WDT = Off
LVP = Off
For 18x chips, type in the config exactly as you would type it in to MPASM. For
example:
For 10x/12x/16x chips, you may use either the 18x format as shown above, or the
default 10x/12x/16x format as used by MPASM:
Random Notes:
When dealing with system registers, the variable name may be omitted and
only the bit specified. For example, SET ADCON0.ADON ON is identical to
SET ADON ON.
GCBASIC is not case sensitive – for example, Wait, WAIT, wait and WaIt
would all be treated identically.
Known Limitations:
Chip Speed: 0.1-60 Mhz
Lines of GCBASIC code (including subs): 20000
Assembly Program: 20000 lines
Include files: 25 (includes built-in include files)
Constants: 400
Variables: approx. 3800 or available RAM on PIC (whichever is less)
Subs (including in include files): 500
Array size: 80 bytes on 10/12/16, 255 bytes on 18 (Avoid large arrays
wherever possible)
String length: 20 characters default, 80 if declared using DIM
Strings: 500