The Great Cow Great Cow BASIC
An open-source BASIC compiler for microcontrollers
Great Cow BASIC Updates


A build of Great Cow Graphical BASIC that includes
  • Added warning when SFR bit names are used as variable names
  • Changed compiler to make use of program space visibility on 16F1xxx - saves code when using fixed strings
  • Fixed bank selection bugs on PIC18Fxxxx
  • Fixed temporary variable bug that was causing problems if an If and a Print statement both used long variables
  • Fixed context saving bug on PIC16F1xxx

  • Fixed bug in bit comparison code on PIC
  • Fixed program memory allocation bug on PIC12F/16F
  • Updated chip data files for some enhanced midrange PIC chips (PIC12F1xxx/PIC16F1xxx)

  • Added Left, Right and Mid functions for string handling
  • Added IndCall command for calling a subroutine using a memory location
  • Added At option to Dim command to allow manual memory allocation
  • Updated help file for above new commands
  • Fixed 32 bit division bug on AVR
  • Fixed string concatenation bug on enhanced mid-range PIC (12F1xxx/16F1xxx chips)
  • Fixed EEPROM library bug on PIC12F1xxx/16F1xxx
  • Fixed timer library bug on PIC12F1xxx/16F1xxx

  • Added Print for Long variables
  • Fixed AVR internal variable bug (Some If statements were not defining their temporary variables properly)

  • Added initial support for KS0108 controlled graphical LCDs (Line, Box, PSet, GLCDPrint and GLCDCLS routines in glcd.h)
  • Added compilation report for more detailed information on subroutine size and locations
  • Fixed bug in STR function
  • Fixed page selection bug for initialisation routines
  • Fixed program memory allocation bug
  • Added initial support for Long (32 bit unsigned) variables:
    • Arithmetic and comparison are supported
    • Data tables supported
    • Print routines are not yet implemented.
  • Added songplay.h library, which provides a QBASIC style Play subroutine, and a PlayRTTTL subroutine for playing ringtones
  • Added chip data for some new PIC microcontrollers
  • Improved add/subtract/logic operators (un-needed high bytes are no longer calculated)
  • Improved array accesses
  • Reduced temporary registers used on AVR for add/subtract
  • Improved AVR register allocation

  • Added warning when pin used for output cannot be used as an output
  • Added HSerPrint for integer variables
  • Fixed AVR string variable bug
  • Fixed several AND/OR/XOR operator bugs
  • Fixed USART library bugs (would not work on ATmega328p, or on any AVR at 16 MHz)
  • Fixed minor chip data errors on ATmega16 and ATmega32.

  • Added AVR support to hardware SPI code
  • Improved setting of SPI clock polarity and phase
  • Fixed bugs which prevented functions that return String variables from working
  • Added working LCase and UCase functions for string case conversion
  • Added Str and Val functions to convert betweeen String and Word variables
  • Fixed bugs when setting some AVR IO registers
  • Fixed bug in software serial routines (error about . in numbers at some clock speeds)

  • Fixed bug in For loop behaviour - condition will now be check at the end of the loop. (If the start and/or end values are variables, it will be checked once at the start before entering the loop.)
  • Using Repeat loop without a repetition count will now give an error message, not an infinite loop
  • Tone subroutine altered to give more accurate frequencies.
  • Fixed context saving bug - ReadTable can now be used in interrupts

  • Added hardware I2C code for PIC
  • Added clock speed setting feature - If no speed is specified, the highest possible internal osc speed will be used. #chip can be used with only the chip name, the comma and speed can be left out.
  • Changed For loop behaviour - condition now checked at start of loop like in FreeBASIC/VB.
  • Added error for Wait with decimal point in delay length.
  • Added warning for clock speeds that are too high.
  • Improved error location reporting for macros.
  • Altered lowlevel includes: ssp.h file split into hwspi.h and hwi2c.h.
  • Fixed Repeat bug when repeat was placed in a subroutine called inside another repeat.
  • Fixed condition bug when NOT or AND used in condition.

  • Fixed array handling bug (some arrays were not being detected properly in subroutines)
  • Fixed Do ... Loop bug (data type of variables used after Loop was not detected properly)

  • Added support for A/D converter of new PIC16F193x chips
  • Improved error messages for Loop without Do, End If without If and Next without For.
  • Fixed A/D initialisation bug on 16C711 (and possibly other PIC chips without a PCFG2 bit)
  • Fixed subroutine placing bug (bankisel was being ignored in sub size calculation, leading to subs in bad places)
  • Fixed crash when opening quotes used without closing quotes
  • Fixed order of operations bug (some calculations were performed right to left, not left to right)

  • Fixed OPTION/OPTION_REG confusion in chip data files
  • Changed behaviour of Repeat loop - Repeat 0 will now repeat 0 times, not 256.

  • Added automatic pin direction setting code - if there is no Dir command for a pin but the pin is used, GCBASIC will detect and set its direction.
  • Added support for Integer data type, which stores 16 bit signed numbers (values from -32768 to 32767).
  • Added Print routine for Integer values.
  • Setting of individual pin directions is now permitted on 12-bit PICs.
  • Removed SysCompLessOrEqual routines from system.h - SysCompLessThan routines will now be used instead, with the parameters reversed and the output inverted.
  • Fixed bug in USART library - received flag is now checked correctly.
  • Fixed assembler bug (from 15/11) which caused AVR string handling to fail.
  • Fixed default oscillator selection bug (PIC).

  • Fixed bank selection bug on PIC 12F/16F (occured when first instruction in subroutine accessed data outside of bank 0)
  • Changed name of constant in random.h - RandomTimer constant is now named RANDOMIZE_SEED.
  • Changed default random seed from TMR0 to Timer0 - now works on both PIC and AVR.
  • Added help articles on pseudo random number generator

  • Fixed interrupt bug on PIC 12F/16F (random crash when interrupt occurs during a call to a subroutine not in page 0)

  • Added automatic pin direction setting (only sets pins if not set by Dir command)
  • Added support for enhanced midrange PICs (tested with PIC16F1936)
  • Added software I2C routines
  • Altered default oscillator settings on PIC:
    • Will now use internal oscillator if it can give the required speed
    • If internal oscillator not suitable, uses HS oscillator for chips over 4 MHz, or XT for under.
  • Fixed page selection bug when dealing with overloaded subroutines
  • Added bit variable comparison
  • Added new LCD mode (allows LCDWriteByte and LCDReadByte to be replaced with custom subroutines)
  • Altered GCASM list file to include symbol table and improved formatting
  • Added pages about USART and software I2C to help file
  • Updated chip data files

  • Fixed bit test bug
  • Fixed 18F compatibility with Tiny PIC Bootloader

  • Fixed several bugs in banksel insertion code on 12F/16F PIC involving loops
  • Fixed banksel bug in built in assembler (added in last update)
  • Added support for #option bootloader [location] to move the start location of the GCBASIC code forward
  • Fixed bugs in word subtraction code
  • Fixed bug in PIC interrupt context save

  • Improved compatibility between new included USART library and that posted on the forums
  • Optimisation improvements:
    • Relative jumps (rcall and bra) now used on PIC 18F where possible
    • Reduced code size for microsecond delay
    • movf, decf, incf used in comparisons to check if variable = 0, 1 or 255 (PIC)
    • If a subroutine is called on the last line of another, call x/return will be replaced with goto x
  • Microsecond delay will now work with variable on all PICs. A warning will be displayed if it will not be accurate (will only be accurate on PIC at clock speeds of 12 + 4x MHz, where x is an integer >= 0).
  • Fixed bug when subtracting word variable from constant (PIC)
  • Fixed PIC delay bug (caused delays of 256 us, 512 us, 768 us, etc to take 256 us too long)
  • Fixed PIC 12F/16F interrupt context save, PCLATH and FSR now saved.

  • Fixed bug in Dir command on AVR.

  • Added USART library, supports both PIC and AVR.

  • Data tables optimised - if a predefined location is to be read, GCBASIC will remove the table and reading code, and set the result variable directly.
  • Fixed bugs in interrupt context save - all calculation variables now saved.
  • Interrupts are now never disabled during calculations - no longer required with improved context save
  • rjmp/jmp and rcall/call now used appropriately on AVR.
  • Fixed IntOn bug - excessive IntOn calls will not cause IntOn/IntOff to stop working.
  • Fixed Interrupt vector/first code location overlap bug (18F and AVR)
  • Interrupt bug on PIC fixed - enable bit now checked as well as flag.
  • .ORG bug in built in assembler fixed (AVR)
  • Timer code now supports AVR.
  • Example programs in help file tidied up.

  • Data tables can now hold word values. GCBASIC will detect data type of table automatically, use a word variable in ReadTable to get word value out of table.
  • Altered included 7 segment and keypad routines. The requirement to connect these devices in a particular way has been removed, and some optimisation has been done to reduce the size of the code. Compatibility with old code has been maintained.
  • Updated included SRF04 ultrasonic routines to add support for the single I/O pin mode used by the SRF05.
  • Support for plug-in file converter modules added, more detail on this to follow.
  • #if compiler directive added.
  • Improved code generated when a long Repeat (> 255 repetitions) was followed by a short repeat.
  • Fixed array bug on AVRs when attempting to access RAM location past 255.
  • Fixed data table bugs (AVR only)
  • Fixed alias to IO register bug (AVR only)
  • Fixed bug when adding different variable types (AVR only)
  • Fixed condition handling bug when condition surrounded by brackets

  • Fixed string parameter bug on 18F chips
  • Improved timing of serial routines. These now run more reliably on slower chips, and at faster speeds (4800 and 9600 bps).
  • Altered handling of branch instructions to make GCBASIC compatible with AVR assembler.


Fixed bugs from 4/5/2009 release:
  • Fixed bug which caused subroutines to be called twice when call command placed before sub name
  • Fixed function bug (invalid calls when variable with similar name to function used in same line)
  • Fixed interrupt bug (context restore code was being placed at the start of the interrupt)
Other fixes/changes:
  • Fixed bug with divide and multiply when multiple banks of RAM used
  • Multiple byte variables will not be split across banks
  • Delay, calculation and interrupt context saving variables now stored in common RAM
  • Added AVR A/D code
  • Added new SerPrint routine to print word variables, SerPrint is now available for byte, word and string.
  • Added subroutine name check in On Interrupt command
  • Fixed error logging bug, too many errors will now result in a "too many errors" error and not a compiler crash.

Major bugs have been encountered in the previous update posted. The previous 24/1/2009 update can be found in and a new update fixing the bugs will be posted in a few days.


  • Major changes to the internal structure of gcbasic.exe:
    • Subroutines are now compiled before being merged
    • Variables are now stored with the subroutine that they belong to, not in a single list.
    • Code is now stored in a doubly linked list, not an array. This should make the compilation process faster.
  • Subroutines will now be moved around between memory pages until they fit. Programs larger than 2048 instructions will be more reliable
  • #option lcall removed, no longer required. Long call instructions will be used automatically where needed.
  • Fixed several bank selection bugs
  • AVR support improved. The following features worked when used on an ATTiny2313:
    • LCD routines (Print, Locate, CLS)
    • Arrays and strings
    • Data tables
    • All calculations and comparisons on byte and word variables
    • On chip EEPROM read and write
    • Delays (us, 10us, ms, 10ms, s)
    • Jumps/Loops (For, Repeat, Do, If, Goto)
    • I/O commands (Dir, Set, PulseOut, Pot)
  • Fixed delay bug, improved accuracy of 10 microsecond and millisecond delays
  • Fixed bug in IntOn/IntOff
  • Fixed bug in 12F683 EEPROM code
  • Fixed several GCASM AVR mode bugs
  • Fixed several chip data file errors.

  • Fixed ReadAD bug that was preventing ports from being set to analog mode correctly
  • Fixed bug in On Interrupt, which was not working properly on chips without PEIE bit.
  • Fixed delay bug which would cause required delay routines to be left out when the delay length involved a calculation.

  • Random function improved
  • Fixed bug when a sub is defined with () following its name
  • Fixed bug which caused issues with long data tables on 18F chips
  • Updated chip data files, fixed several memory map errors

  • Data tables can now be stored in data EEPROM. Define the tables using Store Data directive - for example, "Table TableName Store Data". The data is stored starting at location 0, and filling towards the end of the EEPROM.
  • Support for 18F4331 added to a-d.h
  • Fixed bugs in a-d.h which caused trouble in chips without a CHS2 bit
  • Fixed bug in alias handling which was causing aliases to non-existant variables to be created.

  • Implemented overloading for subroutines
  • Print subroutine now handles Byte and Word variables
  • LCDInt and LCDWord are now deprecated. They will continue to work but Print should be used instead for new programs.
  • Fixed bug when 2 string constants are passed as parameters in the same line
  • Fixed internal bug in WholeINSTR.

  • Fixed bug when using the same array twice on a line
  • Arrays and strings now partially supported on AVRs
  • Fixed bug in GCASM which caused incorrect configuration values on 12C5x/12F5x/16C5x/16F5x PICs
  • The T0CKI pin now defaults to standard I/O mode on 12C5x/12F5x/16C5x/16F5x PICs

  • Altered GCBASIC to read settings from a config file
    • Will read settings from a file called gcbasic.ini in the same directory as gcbasic.exe if present
    • Can read from another file if specified with the /S: parameter
    • See sample file included in update for more detail
    • compile.bat editing utility will be altered, but has not yet been.
    • With a gcbasic.ini file, there is no need for compile.bat. Files can be dropped onto gcbasic.exe.
  • Fixed bug with HPWM
  • Fixed bug when same function is called twice or more on the same line
  • Fixed bug with Dir command on 12-bit core chips with more than 8 pins

  • Added utility to edit compile.bat
  • Updated GCBASIC to compile with FreeBASIC 0.18 (natively, not in -lang deprecated or -lang qb)
    • Successfully compiled and ran on Ubuntu Linux.
  • Altered 4 and 8 bit LCD routines to work without R/W pin when #define LCD_NO_RW is used
  • Strings now default to different sizes depending on chip RAM
  • Added "In" and "Out" to subroutine parameters - for example, "Sub MySub (In Param1, Out Param2 As Word, Param3). In will stop GCBASIC copying the value back from the sub (as with #NR but for each parameter), Out prevents a value being copied in. These are optional.
  • Updated EEPROM subroutines to use In and Out.
  • Fixed bank selection issues related to call mnemonic
  • banksel now only produces code for RP1 if needed
  • bankisel now produces no code on chips with 256 or less data addresses
  • Dir command now checks that pin/port is valid
  • Removed /D: and /NC command line options
    • Improved detection of install directory
    • GCBASIC does not clear the screen any more when running in a command prompt
  • Documented /K:A and /K:C command line options in command line information screen (GCBASIC /?). /K:A will save all original source code as comments in the .asm, /K:C will save all comments from the original source in the .asm.
  • There are now two versions of - which has all of the updated files since the last release, and which has all new files except for the chip data files.

  • Fixed a bug with aliases for user variables which caused assembler errors
  • Allowed use of single character strings as integer constants
  • Minor adjustments to improve bootloader support
  • EEPROM routines updated with new interrupt enable/disable commands
  • Fixed a bug in program memory write routines
  • Fixed array bug introduced in a previous update

  • Added "#option bootloader" - adds an instruction to clear PCLATH at the start of the assembly program, and relocates "call INITSYS" to after the interrupt vector.
  • Added "On Interrupt" for handling interrupts. Please refer to the Interrupts article in the updated included help file for more information (Interrupts is under Syntax).
  • Changed handling of type casts in calculations - instead of being placed on the end, "[word]" must now be placed before the variable or value that is to be cast. "[byte]" is also now allowed. Note that some programs may need to be altered as a result of this change.
  • Changed asm directive - anything following "asm" will now be passed through to assembly even if it is not a valid assembly mnemonic.
  • Fixed LCALL when using asm ORG inside the program.
  • Tidied GCBASIC source code, removed several thousand variable suffixes ($ and %). While some still remain, this is a significant step towards being able to compile GCBASIC with the newest version of FreeBASIC. Many variable names are also now more descriptive than "DS$" or "T%".

  • Added initial AVR EEPROM and ADC routines. These are untested at present.
  • Altered code at reset vector - the InitSys routine is now called from the same location as other initialisation routines. This will allow GCBASIC programs to be used with more bootloaders.
  • Fixed issue with calculation - multiply/divide were sometimes returning incorrect type, or overwriting a required value.
  • Added #IFNDEF directive
  • Minor improvements made to assembly optimisation
  • Initial AVR support added to built-in assembler. Intel hex files produced match those generated by avrasm2, but the code has not been tested on an actual AVR.
  • Rewrote function handling code, now runs significantly faster.
  • Improved pseudo-random number generator
  • Tidied up some older GCBASIC source code
  • Arrays of more than 255 bytes are now permitted on 18Fs.

  • Fixed a bug in the constant folding code for conditions, which caused an error message if the result was true.
  • Added Alias clause to Dim. This enables several smaller variables (typically SFRs) to be combined and treated as one large variable. For example, "Dim EEAddress As Word Alias EEADRH, EEADR" joins EEADRH:EEADR into one word variable named EEAddress.
  • Fixed a bug which caused some word variables to become byte variables.

  • Fixed a bug in timer.h which caused some required code to be deleted
  • Fixed bug in string copy routines when copying empty strings
  • Altered Dim to accept a list of variables, such as "Dim SomeVar, AnotherVar, ThirdVar As String".

  • Partial AVR support added
    • Chip data files
    • Set, Dir, Rotate, Wait, If, Goto
    • Do ... Loop, For ... Next
    • Subs and Functions, including Exit Sub
    • All 8-bit var operations
    • 16-bit equal, not equal, value copy, add, subtract, and/or/etc
    • Generates .asm files compatible with avrasm2
  • Interrupt context saving/restoring
  • Exit Do/Exit For now supported
  • Hardware multiplier code compiled inline - SysMultSub only used for software multiply
  • More error checking

  • Fixed several A/D converter issues on 10F220
  • Fixed bug which may have caused GCBASIC to lock up while sorting the error list
  • Fixed option lcall

  • Fixed a bug which caused confusion between comments and the b' ' notation for binary numbers
  • Major internal changes to the section of code which sets variables, with more to come
  • Alteration to the way that system subroutines (SysCompEqual, SysDivSub, SysCopyString, etc) are added/removed as necessary. GCBASIC now treats subroutines differently when their name starts with "sys".
  • LCDCreateChar (position, sourcearray()) sub added, copies data from an array into the CGRAM of the LCD module
  • Multiple array elements can be set in one line, ie. ArrayName() = 1, 3, 4, 2

  • Fixed bug involving variable type detection
  • Altered ms and us delays to accepts 16-bit delay lengths

  • Fixed several bugs with comments
  • Fixed LFSR command in built-in assembler
  • Fixed issues with hex numbers in assembler.

This site is hosted for free by Logo