Great Cow Basic Notes
These notes document information not yet in the help file, or bugs not yet fixed, or just other information related to GCBasic. Its most important source may be the forums. It is in no way guaranteed to be complete or 100 percent accurate. See sources at end of document. This should in particular help you avoid searching all the forums for information. When the undocumented is documented, or the bug fixed, the note will be sorted to the bottom of the document, and there will be a note in the disposition.
Documentation ( help file ) has not yet be reviewed so some of these may already be in the help file.
This document version January 13, 2007 Additional copy of this may be found at http://home.comcast.net/~russ_hensel/RClub/GCBNotes.html
Comments or suggestions about this document: send to struve13 (at) verizon.net
|
Ref |
Note |
Disposition |
|
001 |
You can compile by dragging ( in windows explorer ) your source file on compile.bat |
May be in docs. Repeated later in Notes |
|
002 |
For the latest version of GCBasic you may need: http://gcbasic.sourceforge.net/newfiles/update.zip The update.zip file contains a new executable dated xx/xx/xxxx and some new header files. Extract it to your GCBASIC folder, and it will overwrite the old ones. update.zip may sometimes contain more bugs than the current version, and so should not be downloaded unless a particular problem is being experienced and update.zip is known to contain a fix. |
May be in docs. |
|
003 |
Using assembler code: Put the code inline in your source code. They should be passed thru to the assembly file. GCBASIC should recognize all of the ones in the PIC datasheet. When it puts them into the assembly, it is supposed to format them like this:
btfsc STATUS,Z bsf PORTB,1
That is, they should be in lower case and have a space or tab in front of them.
Even if the mnemonics are not being formatted properly, gputils/MPASM should still be able to assemble the program. |
Docs not yet checked. |
|
4 |
General operation. GCBASIC.EXE takes a text source code file and converts it to an assembler file. This is output in the same directory as the source code file. This is all done in a “dos box” without a graphical user interface. Using GCBASIC.EXE <source file name> from the GCBASIC.EXE directory should accomplish this. However in most cases you will want to do this by dragging ( in windows explorer ) your source file on compile.bat This will also pass the asm file onto gpasm. MPLab should also be able to assemble the file. Note that MPLab also has a simulator for testing the code ( not easy to use, requires some knowledge of assembler. If you are having trouble look at COMPILE.BAT and MAKESAM.BAT ( in the GCBasic directory ) they may need some tweaking if you have not installed in the normal locations. |
Docs not yet checked. |
|
5 |
The frequency range allowed for PWM depends on the speed of the PIC - the help file has approximate limits. I have prepared a spreadsheet that can calculate whether or not a particular speed chip can handle a given frequency. It is now online at http://gcbasic.sourceforge.net/PWMCalc.xls
|
Docs not yet checked. |
|
6 |
The 2 bit LCD routines are not intended for serial LCD display. Use them if you want to drive standard LCD display using only two I/O pins plus some additional hardware. For a circuit schematics example see http://www.rentron.com/Myke1.htm |
Docs not yet checked. |
|
7 |
The syntax for calling a subroutine with parameters is HPWM 1, 4, 127 not HPWM ( 1, 4, 127 ). |
Docs not yet checked. |
|
8 |
Software PWM is also implemented now, using the PWMOut sub. It is difficult to adjust for a specific frequency, but it works well for controlling the brightness of LEDs and assumedly other items. |
Docs not yet checked. |
|
9 |
Hardware PWM doesn't work because CCP1CON<5:4> registers has different name. Tried to rename pwm file and convert, but then had another problem.
Have tried to set the registers manually, and probably close to getting the job done. A bit unsure how you initialize, clear, and set CCP1. Just checking with a DVM for expected frequency at the moment.
From the datasheet, it looks like Microchip have just renamed a few bits. Adding these lines to pwm.h or your program should make it work:
#define CCP1X DC1B1 #define CCP1Y DC1B0
To enable PWM, the subroutine PWMOn is called. This copies the value out of CCPCONCache and into CCP1CON. The PWMOff sub clears CCP1CON and thus disables PWM. InitPWM is called automatically at the start of the program if you use PWMOn or PWMOff. |
Fixed in GCBASIC 0.9.3.0 (and later) |
|
10 |
In GCBASIC, all variables are defined automatically as bytes, unless DIM is used to set them to words (DIM VariableName AS Word) or bits (DIM VariableName As Bit). Nibbles are not supported at present. 2D arrays are also not supported at present, unfortunately. |
|
|
11 |
Infinite loop: do . Instructions . loop but could also do a goto to a label up at the top of the loop. |
|
|
12 |
GCBASIC has support for the built in SPI module that is on many PIC chips. SPI uses 3 wires - send data, receive data and clock. With a few diodes, it should be possible to connect the data lines of your devices to the PIC send and receive pins. |
|
|
13 |
The example program should read as follows:
'This program will send a byte using PORTB.2, the value of which 'depends on whether a button is pressed.
#define SendAHigh SET PORTB.2 ON #define SendALow SET PORTB.2 OFF
dir PORTB.2 out InitSer (1, r9600, 1+WaitForStart, 8, 1, none, normal)
Main: if Button pressed then Temp = 0 if Button released then Temp = 100 SerSend (1, Temp) Wait 1 s goto Main
It is possible to use the same pin to send and receive - this would require the use of a DIR command to change the port direction.
The older help articles were written to show the syntax of the command more than an actual working program, so that program is missing a few things (such as #chip). The #defines are something I missed when adapting the receive example to show a send. The older incomplete examples are gradually being replaced by newer ones that are ready to run with only minor changes, or no changes at all.
The use of letters and numbers is admittedly odd. Rec1High, Send1High etc will be made valid in the next version of GCBASIC.
There are already a few issues with the serial that need to be dealt with such as the maximum baud rate. If you have any more trouble or confusion please don't hesitate to post. |
|
|
14 |
Strings in GCBASIC are just arrays. dim StringName(40) has exactly the same effect as dim StringName as string * 40. The dollar sign works the same way as the () in GCBASIC - it is used when referring to the string/array as a whole. |
|
|
15 |
SerPrint is completely untested, and there is no SerRead yet. I'd recommend avoiding them both. |
|
|
16 |
The morse code demo ( http://gcbasic.sourceforge.net/morse code.txt ) shows how to work with arrays to store strings of characters. lego.h might also be of interest - there are a few routines in there that send out an array using rs232. In particular, have a look at SendOpcode. |
|
|
017 |
sub SerRead(Channel, SerReadData(), numbytes) for Counter = 1 to numbytes SerReceive Channel, SerReadData(Counter) next end sub
To read 10 bytes into message$, use SerRead(1, message$, 10). I'll probably add this to the next version of GCBASIC. |
|
|
018 |
By default GCBASIC will turn off the watchdog timer. |
|
|
019 |
The "pot" command in GCBASIC is less flexible than that of PICBASIC - see http://gcbasic.sourceforge.net/help/pot.htm for more. |
|
|
020 |
http://gcbasic.sourceforge.net/morse%20code.txt not in downloaded demos. |
Added in GCBASIC 0.9.3.0 |
|
021 |
The current version of GCBASIC doesn't have interrupts implemented fully. However, with the latest update at http://gcbasic.sourceforge.net/newfiles/update.zip it is possible to insert code at the interrupt vector, which is run whenever an interrupt occurs.
To add an interrupt routine, create a subroutine called "Interrupt". This will be called whenever an interrupt occurs. You'll need to set up the interrupt manually, as GCBASIC doesn't yet have the ability to do this. |
|
|
022 |
For LCD display: The circuitry is explained here:
As for the programming, you'll need to set three constants using #define - set LCD_IO to 2, LCD_DB to the data pin, and LCD_CB to the clock pin on the PIC. Then, you can use all of the LCD commands such as PRINT and LCDInt. |
|
|
023 |
It is possible to use binary numbers in GCBASIC, as long as you use "b'" to mark the numbers as binary. For example, this will work: A(2) = b'00110011' As will this: A(2) = 0b00110011
|
|
|
024 |
Incidentally, hexadecimal can also be used - add 0x to the start of a number to mark it as hex, or use h'number'. |
|
|
025 |
For input ports On ( as in If xxx On ) on corresponds to a high, non zero voltage on the input port bit. |
|
|
026 |
Not is used as a prefix operator ex: Not TrainPresent. As in the demo Level Crossing.txt As in: if not a_variable then |
|
|
027 |
config #config INTOSC_OSC_NOCLKOUT, MCLRE_OFF is ok but config #config INTOSC_OSC_NOCLKOUT MCLRE_OFF ( missing comma ) compiles without error, but is ng in MPLab |
Fixed - Error generated in GCBASIC 0.9.3.0 |
|
028 |
Keycount=((Rowcount-1)*4) + 1 compiles incorrectly, reported, may have been fixed. ( By: Stefano Bonomi (trantor_65) - 2006-10-20 04:58 ) |
|
|
029 |
GCBasic is generally case insensitive, but asm output may not be consistently capitalized. MPLab is case sensitive by default. If using MPLab turn off its case insensitivity ( in project properties? ) Also in MPLab turn off case sensitivity with /c- command line switch. To turn it off in gputils, use the "-i" switch. |
|
|
030 |
GCBASIC should warn if too much memory is used. |
|
|
031 |
On the 12F508 and some other low level chips, it is only possible to set the direction of the whole port at once. This is a limitation of some PIC chips, and I'll add an error to GCBASIC to warn of this. |
Error added in GCBASIC 0.9.3.0 |
|
032 |
In some cases the compiler may have an incorrect default for the ossc config. If so the assembler may complain of an illegal oscillator setting. You may want to double check the oscillator setting and override the default if incorrect. |
|
|
33 |
GCBASIC is programmed to look for the header files in 3 locations - the MPLAB default location, the gputils default location, or a subdirectory of the GCBASIC folder called "MPASM". Basically GCBASIC will work fine if you go to C:\Program Files\GCBASIC, create a folder called "MPASM", and then copy the necessary .inc files into it. |
GCBASIC no longer reads the header files (0.9.3.0) |
|
34 |
tone(325,100) - The frequency is now input in Hz, not in Hz x 10 - The maximum frequency is now 20000 Hz (although higher frequencies do not work very well) |
|
|
35 |
It would seem that I have neglected to document the way that the ROTATE command works properly!
This is a result of the way that the rlf and rrf assembly mnemonics work - STATUS.C acts as a ninth bit of the variable that is being rotated. When a variable is rotated right, STATUS.C is placed into the MSB of the variable Rotation, and the LSB of Rotation is placed into STATUS.C.
For now, the way to work around this is to add some code to set STATUS.C to the least significant bit of the variable, like this:
SET STATUS.C OFF IF Rotation.0 ON THEN SET STATUS.C ON Rotate Rotation right
This will make your program work as expected. In the next version of GCBASIC, I'll fix the documentation and add an option to the Rotate command so that it can be made to add those lines automatically if desired. |
Fixed in 0.9.3.0 |
|
36 |
In GCBASIC at present, binary is represented like this:
b'01010101' And hex like this: 0xAB
In the newest version of GCBASIC, h'AB' and 0b01010101 are also supported. |
Fixed in 0.9.3.0 |
|
37 |
In GCBASIC, true and false are represented by values of 255 and 0 respectively. Hence while the and/or/xor functions are bitwise, they will also work logically.
|
|
|
38 |
All control structures can be nested. |
|
|
39 |
For .. Next will work with byte and word variables. |
|
|
40 |
Test a bit with if Temp.0 off then gosub 0 |
|
|
|
|
|
|
41 |
If Then: GCBASIC does not yet support else, so two ifs must be used. This is not entirely bad - the assembly code generated by the ifs in this program is much more efficient than the code produced by else would be. |
|
|
42 |
If you want to step through you code you can do it in the assembled version using MPLab. |
|
|
|
|
|
|
|
|
|
Sources for the notes:
|
Source |
Extracted thru |
|
Forum: Compiler Problems |
2007-01-16 16:23 |
|
Forum: Help |
2007-01-03 10:23 |
|
Tutorial |
None |
|
WebSite: Tracker |
None, not in use? |
|
|
|