A Review of LET's PIC BASIC Compiler |
![]() |
Version 4.6 of the LET BASIC compiler is the target of this review. Subsequently, information was found on the web re: commercial compilers derived from LET's original product, by Crownhill Associates.
For version 4.6:
web: http://let.cambs.net
email: johnmorr@keyworld.net
For newer versions by Crownhill Associates:
web: http://www.letbasic.com
PIC BASIC version 4.6 is on the SA PIC User Group's CD. See also the Vendor Information above.
The IDE is a simple Windows application with 3 panes: source, assembly output, and messages. Standard toolbar and menus make it easy to start using. The Help menu contains a useful command syntax summary item.
The main language features are:
A PIC BASIC program is required to have a certain structure, with declaration commands (DEVICE, DEFINE, DIM etc) before all others. Here is a short program which briefly produces a higher and higher pitched sound and flashes a LED each time a button is pressed. Note that lines starting with a quote are comments. Other aspects of code format are also prescribed, such as that labels must appear in column 1, spaces must appear around a colon in multi-statements, and so on.
' Sound and button tests using my simple PIC development board. ' RA0 -> button (input) ' RB0 -> piezo (active low output) ' RB7 -> LED (active low output) Device 16F84 Define PORTA=11111111 Define PORTB=00000000 Dim pitch, length pitch = 200 length = 200 Loop: Set B.7 Button A.0 Clear B.7 pitch = pitch - 10 : if pitch = 0 then pitch = 200 Sound(pitch,length,B.0) Goto Loop End
Instead of using pin specifications such as A.0 and B.7 one can assign a name such as myButton and myLED via the SYMBOL command for use in SET, CLEAR, BUTTON, and SOUND commands.
PIC BASIC doesn't require code from libraries, generating all the code needed. This at least is true of the Lite version.
I wrote a simple clock program and found that code generated for multiplication and division was buggy. The lack of a MOD (remainder) operator and bitwise NOT (1's complement) seem strange are were missed. Given integer arithmetic, a quotient (Q), divisor (D), and dividend (N), MOD can be replaced by N-Q*D, but bitwise negation requires inline assembly via PIC BASIC's ASM directive.
LET sells a parallel port PIC Programmer, and an IDE menu item allows a PIC to be programmed using it. Since my programmer (a Jaycar kit by Charles Manning) is not compatible with LET's, I used MPLAB to assemble the code generated by the compiler, and P16Pro-Lite to program a 16F84A.
On the whole, PIC BASIC generates efficient assembly, but see the next section.
Section 4.1 in the PDF file says that "Add, Subtract, and Multiply need no explanation we hope", but they do! What for example happens if I add 250 and 40? Do I get 290 or 2? The answer depends upon whether integer arithmetic is limited to 8-bit words, which it is in PIC BASIC.
No information about operator precedence and associativity is given in the
documentation (PDF or Help menu). For example, what will be the result of
the expression 12+2*3, 18 or 42? If multiplication has a higher
precedence than addition, the former. As it turns out, by experimentation I
found that there is no precedence, at least not for + and *, since
the answer is 42. Moreover, there is apparently no way to change the
precedence by parenthesising sub-expressions, eg 12+(2*3) or
(12+2)*3.
PIC BASIC uses C-style operators such as >>, << (shift right and left), &, | (bitwise AND and OR), but changes the meaning of "!" from bitwise NOT to XOR, which in C uses the symbol "^".
There are other expression evaluation problems, listed below.
The introductory section in the PDF documentation proclaims that "Unlike other 'BASIC' compilers around, many of which bear little resemblance to real BASIC, the authors of this version have tried to keep as much to the original ideals of BASIC as possible." An essay could be written on this topic, but the claim is essentially specious. Which BASIC do the authors mean? Microsoft derivatives? Kemeny and Kurtz's original Dartmouth BASIC? Their more recent True BASIC? There is no implementation of BASIC standards, only defactos such as Microsoft dialects (eg QuickBasic, VB, Amiga BASIC), and True BASIC, despite the existence of ANSI BASIC standards.
In no particular order, here are most of the other problems I found with PIC BASIC, in many cases framed as questions. If any answers are forthcoming, I will add them inline below later. Given that this is no longer a supported version of the product, that may be unreasonable.
z = x*10 should use a combination of one left shift and two additions rather than repeated additions, which
reduces the number of instructions by half.x = -12 or x = -x and division in some cases.Since LET have ceased trading and the product has been taken up by Crownhill Associates, many of the problems listed above have been addressed. This comes at a higher cost however since it is essentially now another commercial offering. The newer versions add: modulus, some 16/32-bit operations, parentheses in expressions, operator precedence, some features closely aligned with Basic Micro's BASIC, eg REPEAT, WHILE, negative steps in FOR loops, PWM, RANDOM, SERVO. Other useful additions are ELSE..ENDIF, INCLUDE, and hardware interrupt handling. Still no support for bitwise NOT or SUBs exists however. Lite compilers for Plus and Pro versions exist, but are more restrictive than LET BASIC 4.6 insofar as maximum lines of code permitted etc.
| Compiler | Vendor/Author | Cost | Comments |
|---|---|---|---|
| Basic 18 | Eric James | $30 for Standard version, $50 for Professional version, $180 and $300 for corresponding site licenses. | Limited to PIC 18x series. Nice BASIC dialect, permitting SUBs. |
| CH Basic | Celestial Horizons Pty Ltd | $30 for Bronze version, $95 for Flash version ($110 on CD). | The Bronze edition has a very limited set of commands. Free trials can be downloaded from the web. Shows assembly output. Requires program editing line-by-line via buttons and dialog boxes. |
| PicBasic Pro | microEngineering Labs, Inc. | $99.95 for PicBasic compiler, $249.95 for PicBasic Pro. | Basic Stamp compatible commands. Freely downloadable Windows Integrated Development Environment, but no free trial version that I could find. See also the UK web site http://www.picbasic.co.uk/ |
| FED PICmicro® MCU Basic (manual refers to it as PIC Controller Basic) | Forest Electronic Developments | ~£100 including development board and CD. | Compiles BASIC to p-codes which are interpreted by an EEPROM-based interpreter on a special PIC development board. Similar idea to BASIC Stamp. The available development board appears to be limited to 40 pin PICs. There are 16 and 32 bit versions of the BASIC compiler, and the first is free. This BASIC dialect, like so many microcontroller BASICs, has obviously been influenced by the C language. Variables of many different sizes are supported (1..8, 15, 16 bits), and there is a rich set of commands and built-in functions. While interesting, this compiler does not produce PIC assembly, so is of limited value. |
| MBasic | Basic Micro | MBasic Standard is $99.95, MBasic Professional is $179.95. | Basic Stamp compatible. Windows IDE. Many useful commands and functions - the web pages list these. The web page does not appear to offer any free trial of MBasic. |
I downloaded and briefly tried FED PICmicro® MCU Basic and CH Basic. The first is probably not worth further consideration since despite being a fairly mature BASIC dialect, it generates p-codes, not native PIC code.
CH Basic looks okay, but the interface, at least for the Bronze edition, is better suited to the beginner than the serious user, not a bad thing, just a limitation. Since the Bronze and Flash versions are available for free trial, both may be worth further investigation.
Basic 18 may also be worth investigation despite its limitation to 18x series PICs. Assuming it is reasonable in other regards, perhaps the author could be convinced to add support for the 16F84 and so on.
The price of the Lite version is certainly right. I cannot comment upon the suitability of the Pro version since I don't have it.
PIC BASIC has educational value since one can easily see the correspondence between BASIC source lines and assembly code produced since the former are included as comments in the generated code, as Miroslav pointed out at a SA PIC user group meeting several months ago when demonstrating PIC BASIC.
It is also useful for prototyping ideas, which could if so desired, be subsequently rewritten in another language, or used as-is.
LET has done a nice job of PIC BASIC, and I appreciate how much work is involved, but improvement is possible. As it stands, I would be more likely to use it for quick prototyping than for producing the final code of a project. With improvements, it could be used for more.
Since newer versions are commercial, support for 4.6 shouldn't be expected. By all means however, make use of PIC BASIC 4.6, at least for experimentation purposes.
The question now is whether the club is willing to purchase an appropriate compiler licence for more general use. If not, what is still needed is a free, supported PIC BASIC compiler for the PIC for the club. One possibility is for us to take on the development of such a compiler as a club project, no small undertaking, but possible.