Page 1 of 1

Great Cow Basic Development Environment Quick Start Guide

Posted: Thu Aug 07, 2014 5:53 pm
by admin
Image

To help our customers who are new to the PIC microcontroller, or programming in general, and need a quick and way to get started we have created this thread which describes how to install and use the excellent Great Cow Basic programming language and the development environment. Great Cow BASIC is an open-source BASIC compiler released under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License and is freely available for download. It provides one of the easiest ways to develop code for the 8 Bit Microchip PIC microcontrollers. We have tailored this quick start guide towards installing the software and using it with our development board and programmers.

Disclaimer: We are not affiliated with this project any any reports of bugs or other issues with this software should not be directed to Hobby Components. Use of this software is at your own risk and we cannot accept any responsibility for loss or damaged caused by its use.

Installation:
First of all you will need to download the the software or development environment to allow you to create your own programs. The downloads section for the main project homepage can be found on sourceforge here:

http://gcbasic.sourceforge.net/download.html

For this guide we recommend downloading the GCB@Syn development environment created and maintained by Frank Steinberg here:

http://sourceforge.net/projects/gcbasic ... p/download

This will download a zip file to your computer. Once downloaded, unzip the folder and copy it to a convenient place on your computer. For this guide we will assume this is to the top level of your C: drive.
Image

Do not copy the folder to your windows program files folder as it may not run properly from there. You should now have a folder on your C: drive called GCB@Syn which contains a number of files including one called IDE.exe. This is the main executable for the IDE, but before we run it we need to configure the software to work with a programmer. At the time of writing this guide we currently stock two types of PIC programmers that are compatible with this IDE:


K150 Pic programmer (HCDVBD0002)
http://hobbycomponents.com/index.php/pi ... ammer.html

Pickit2 compatible programmer and debugger (HCDVBD0020)
http://hobbycomponents.com/index.php/pi ... ugger.html


Installing the correct software for your programmer:

The IDE you have just downloaded doesn't contain software for your programmer but it does contain place holder folders for you to download the appropriate software and copy the programmer software to.

For the K150 programmer:

This can be downloaded from our support forum at the following location:

http://forum.hobbycomponents.com/viewto ... =44&t=1344

You will need to be logged into the forum to be able to download the files. First of all download the 'PIC Program Software English Version.zip' file. Unzip this to anywhere on your computer and copy all the files within this folder to the following location:

C:\GCB@Syn\K150

Image

Next download the prolific drivers from the following location:

http://www.prolific.com.tw/US/ShowProdu ... 25&pcid=41

Unzip and install, then plug your K150 programmer into a USB port on your computer. Once the drivers have installed you will need to determine what COM port has been associated with your K150 programmer. This can be found by opening up device manager in windows.

Image

Make a note of the COM port number as you will require this later.


For the Pickit2 compatible programmer:

A command line version of the programming software can be downloaded from the Microchip website here:

http://www.microchip.com/DevelopmentToo ... O=pg164120

On this page locate the PK2CMD vX.XX PICkit 2 Command Line Interface zip file and download it.

Unzip this anywhere on your computer and copy the contents to the following folder:

C:\GCB@Syn\PicKit2

Image



Configuring the IDE for your programmer:

You will need to locate the following batch file and open it in a suitable text editor:

C:\GCB@Syn\G@Stools\flashPIC.bat

This file contains default settings for various types of PIC programmers. Most of these setting are 'commented out' with the word REM at the beginning of the line which means the line is ignored, but by default there will be an uncommented line enabling the PICpgm programmer:

Code: Select all

"PICPgm\picpgm.exe" -delay 1 -p %1
If you don't intend to use this programmer you can comment this line out by adding a REM as follows:

Code: Select all

REM "PICPgm\picpgm.exe" -delay 1 -p %1
If you wish to use the K150 programmer locate the following line:

Code: Select all

REM "K150\microbrn.exe" %1 %2 /f /Q 2
And change it to:

Code: Select all

"K150\microbrn.exe" %1 %2 /f /Q 2
For the K150 programmer it is also important to set the correct com port. As previously instructed you should have made a note of the current com port. You will need to change the value and the end of this line to match the com port associated with your K150 programmer. For instance if your programmer is currently associated with com port 2 (COM2) then change the number at the end of the line to:

Code: Select all

"K150\microbrn.exe" %1 %2 /f /Q 2

If you wish to use the Pickit2 compatible programmer then locate the following line:

Code: Select all

REM "PicKit2\pk2cmd.exe" -b"%G@SDir%\PicKit2" -pPIC%2 -f%1 -m
And change it to:

Code: Select all

"PicKit2\pk2cmd.exe" -b"%G@SDir%\PicKit2" -pPIC%2 -f%1 -m
You can have more that one programmer uncommented at the same time and the software will try and detect which programmer is connected, but if you only plan to use one programmer, then it is best to comment out the rest with REM statements. Save this batch file and then close it. The IDE can now be loaded by double clicking the IDE.exe file in the main folder.


Example Programs:

If you have followed the above instructions correctly you should now have a working GCB environment and can now start writing programs for your development board. Below are a couple of example programs which you can just cut and past to the main window in the GCB IDE. To compile and flash the program to your development board just hit the yellow/green button on the tool bar labeled 'Hex Flash'.


Blink Example Programs:

Forum user Anobium has very kindly contributed an example program that will make all the LED's connected to PORTD on the 16F8777A development board blink:

Code: Select all

'   FILE:    PIC_16F877a_LED_Test.gcb
'   DATE:    01/08/14
'   VERSION: 0.1a
'   AUTHOR:  Anobium, based on the work of Andrew Davies dated 26/07/14

'  This test program will flash the LEDs connected to port D on the development board.
'  It was written using the Great Cow Basic (GCB) complier. Install GCB - you are recommended to use
'  GCB@SYN from the Great Cow Basic website.

'    This code is free software; you can redistribute it and/or
'    modify it under the terms of the GNU Lesser General Public
'    License as published by the Free Software Foundation; either
'    version 2.1 of the License, or (at your option) any later version.

'    This code is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
'    Lesser General Public License for more details.

'    If you require a copy of the GNU Lesser General Public
'    License along with this code; please write to the Free Software
'    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

'Chip settings
  #chip 16F877a, 4    ' Select the chip and the chip speed
  #config Osc = XT    ' Select the external oscillator

  dir portd out         ' Set all PORTD ports as outputs

  do forever            ' Loop for ever

      PORTD=0xFF      'Turn off LED's on port D
      wait 125 ms       'wait

      PORTD=0x00      ' Turn on LED's on port D
      wait 125 ms       'wait
  loop

LCD Example Program:

The following program can be used together with the 16F877A development board and one of our 1602 parallel LCD modules to demonstrate the ease of displaying text using GCB.

Code: Select all

'  FILE:    PIC_GCB_16F877a_LCD_Example
'  DATE:    07/08/14
'  VERSION: 0.1
'  AUTHOR:  Andrew Davies
'
'This program was written using the Great Cow Basic IDE for use with our PIC 
'16F8777A development board (HCDVBD0003) and our 1602 parallel LCD module 
'(HCMODU0013 or HCMODU0038) to display some example text.
'
'You may copy, alter and reuse this code in any way you like, but please leave
'reference to HobbyComponents.com in your comments if you redistribute this code.
'This software may not be used directly for the purpose of selling products that
'directly compete with Hobby Components Ltd's own range of products.
'
'THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, 
'WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
'WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
'LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
'FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR 
'CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER.




'Chip Settings. Assumes our 16F877A development board with with external 4MHz 
' crystal
#chip 16F877A,4

'Use LCD in 4 pin mode and define LCD pins
 #define LCD_IO 4
 #define LCD_RW PORTE.1
 #define LCD_RS PORTE.0
 #define LCD_Enable PORTE.2
 #define LCD_DB4 PORTD.4
 #define LCD_DB5 PORTD.5
 #define LCD_DB6 PORTD.6
 #define LCD_DB7 PORTD.7


'Main program 
 Main:
 
   'Clear the LCD
   CLS
   
   'Display some text on both lines
   Locate 0,5  
   Print "HOBBY" 
   locate 1,3 '
   print "COMPONENTS"

  'Do nothing
   Do Loop

 Goto Main

GCB_16F1939_LCD_Example using PIC40 Board.

Posted: Mon Aug 11, 2014 2:03 pm
by Anobium
This code support an 1602 LCD from 0.125 to 16 MHz using a 16F1939 chip. This example is set to 16mhz

Code: Select all

'  FILE:    PIC_GCB_16F1939_LCD_Example
'  DATE:    07/08/14
'  VERSION: 0.1
'  AUTHOR:  Anobium
'
'This program was written using the Great Cow Basic IDE for use with the PIC
'16F8777A development board (HCDVBD0003) and a standar 1602 parallel LCD module
'to display some example text.
'
'You may copy, alter and reuse this code in any way you like, but please leave
'references in your comments if you redistribute this code.
'
'THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES,
'WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
'WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
'LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
'FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR
'CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER.


'Chip Settings. Assumes the development board with a PIC16F1939 between 0.125 and 16 mhz
#chip 16F1939,16

'Use LCD in 4 pin mode and define LCD pins
 #define LCD_IO 4
 #define LCD_RW PORTE.1
 #define LCD_RS PORTE.0
 #define LCD_Enable PORTE.2
 #define LCD_DB4 PORTD.4
 #define LCD_DB5 PORTD.5
 #define LCD_DB6 PORTD.6
 #define LCD_DB7 PORTD.7


'Main program

   'Clear the LCD
   CLS
   'Display some text on both lines
   Locate 0,0
   Print "HOBBY COMPONENTS"
   wait 1 s
   CLS
   print "16F1939 @ "+str(ChipMhz) + "Mhz"
   Locate 1,0
   print "by Anobium"