BASIC Stamp, Microchip PIC, 8051, and Remote Control Projects

Our most popular PBP bundle now includes a FREE
CD-ROM with our A/D logging software
shown here http://www.rentron.com/AD_LOG.htm

and PBP remote control code examples shown here
http://www.rentron.com/QRELAY.htm

 

Click this link for details PicBasic Pro Compiler/Programmer Bundle

What is a PIC BASIC Compiler, and what can it do for "ME"..?

This is one question we answer more than any other, and a very good one. This page will help you understand what the PicBasic compiler is, and why it's worth every penny of the initial investment.

I think the following will provide an incredibly clear understanding of the difference between writing code for the PIC microcontroller in assembly vs. PicBasic.

Some time ago Scott Edwards produced a book titled: "The PIC Source Book". Scott's book was a collection of ready-to-use assembly language routines based on the instruction set of the BASIC Stamp single-board computer. The idea was to provide people with functional PIC assembly code that would allow them to emulate the commands available with the BASIC Stamp, but directly with the PIC microcontroller, and in assembly language.

Scott no longer sells this book, and has made the assembly code available to the public. I'll use his examples here to demonstrate "in black & white" how much time the PicBasic compiler will save you.

The following examples will show "single-line commands" with PicBasic, and the equivalent assembly language required for the same results. Notice how simple "single-line" PicBasic commands will take considerably more time & effort to emulate in assembly language.

Note:  The assembly language equivalents are so large that whole html pages have been created specifically for each one. Click on the links to view the assembly equivalents, then click the link at the bottom of each page to return here.

Command: Receive serial data on a single I/O-pin
PicBasic Pro:
SERIN 0, N2400, ["A"] ' Wait for the ASCII character A on port-pin 0 at 2400 baud
Assembly Language Equivalent: Click HERE

Command: Output a PWM pulse train on an I/O-pin
PicBasic Pro: PWM Pin, Duty, Cycle ' Output PWM on Pin at duty-cycle, for specified number of cycles.
Assembly Language Equivalent: Click HERE

Command: Generate a pulse on Pin for specified Period
PicBasic Pro: PULSOUT Pin, Period ' Output pulse on Pin for specified Period.
Assembly Language Equivalent: Click HERE

Command: Pause program operation for a number of milliseconds
PicBasic Pro: PAUSE Period ' Pause program operation for Period in milliseconds.
Assembly Language Equivalent: Click HERE

As shown above it's easy to see how assembly language can take "pages of code", just to emulate simple "single-line commands" available with PicBasic Pro. What you can do with a few key-strokes in PicBasic Pro can take several pages of assembly.

Above are only very simple examples. Imagine trying to recreate even a few of the commands listed below in assembly language. PicBasic Pro version 2.4 includes several new commands. Version 2.4 new commands are shown in blue below:

 @ Insert one line of assembly language code.
ADCIN
Read on-chip analog to digital converter.
ASM..ENDASM
Insert assembly language code section.
BRANCH
Computed GOTO (equiv. to ON..GOTO).
BRANCHL
BRANCH out of page (long BRANCH).

BUTTON
Debounce and auto-repeat input on specified pin.
CALL
Call assembly language subroutine.
CLEAR
Zero all variables.
CLEARWDT
Clear (tickle) Watchdog Timer.
COUNT
Count number of pulses on a pin.
DATA
Define initial contents of on-chip EEPROM.
DEBUG
Asynchronous serial output to fixed pin and baud.
DEBUGIN
Asynchronous serial input from fixed pin and baud.
DISABLE
Disable ON DEBUG and ON INTERRUPT processing.
DISABLE DEBUG
Disable ON DEBUG processing.
DISABLE INTERRUPT
Disable ON INTERRUPT processing.
DTMFOUT
Produce touch-tones on a pin.
EEPROM
Define initial contents of on-chip EEPROM.
ENABLE
Enable ON DEBUG and ON INTERRUPT processing.
ENABLE DEBUG
Enable ON DEBUG processing.
ENABLE INTERRUPT
Enable ON INTERRUPT processing.
END
Stop execution and enter low power mode.
FOR
..NEXT Repeatedly execute statements.
FREQOUT
Produce up to 2 frequencies on a pin.
GOSUB
Call BASIC subroutine at specified label.
GOTO
Continue execution at specified label.
HIGH Make pin output high.
HPWM
Output hardware pulse width modulated pulse train.
HSERIN
Hardware asynchronous serial input.
HSEROUT
Hardware asynchronous serial output.
I2CREAD
Read from I2C device.
I2CWRITE
Write to I2C device.
IF..THEN..ELSE..ENDIF
Conditionally execute statements.
INPUT
Make pin an input.
LCDIN
Read from LCD RAM.
LCDOUT
Display characters on LCD.
{LET}
Assign result of an expression to a variable.
LOOKDOWN
Search constant table for value.
LOOKDOWN2
Search constant / variable table for value.
LOOKUP
Fetch constant value from table.
LOOKUP2
Fetch constant / variable value from table.
LOW
Make pin output low.
NAP Power down processor for short period of time.
ON DEBUG
Execute BASIC debug monitor.
ON INTERRUPT
Execute BASIC subroutine on an interrupt.
OWIN
One-wire input.
OWOUT
One-wire output.
OUTPUT
Make pin an output.
PAUSE
Delay (1mSec resolution).
PAUSEUS
Delay (1uSec resolution).
PEEK
Read byte from register.
POKE
Write byte to register.
POT
Read potentiometer on specified pin.
PULSIN
Measure pulse width on a pin.
PULSOUT
Generate pulse to a pin.
PWM
Output pulse width modulated pulse train to pin.
RANDOM
Generate pseudo-random number.
RCTIME
Measure pulse width on a pin.
READ
Read byte from on-chip EEPROM.
READCODE
Read word from code memory.
RESUME
Continue execution after interrupt handling.
RETURN
Continue at statement following last GOSUB.
REVERSE
Make output pin an input or an input pin an output.
SELECT CASE
Compare a variable with different values.
SERIN
Asynchronous serial input (BS1 style).
SERIN2
Asynchronous serial input (BS2 style).
SEROUT
Asynchronous serial output (BS1 style).
SEROUT2
Asynchronous serial output (BS2 style).
SHIFTIN
Synchronous serial input.
SHIFTOUT
Synchronous serial output.
SLEEP
Power down processor for a period of time.
SOUND
Generate tone or white-noise on specified pin.
STOP
Stop program execution.
SWAP Exchange the values of two variables.
TOGGLE
Make pin output and toggle state.
USBIN
USB input.
USBINIT
Initialize USB.
USBOUT
USB output.
WHILE..WEND
Execute statements while condition is true.
WRITE
Write byte to on-chip EEPROM.
WRITECODE
Write word to code memory.
XIN
X-10 input.
XOUT
X-10 output.

PicBasic Pro allows you to type in a "single command" that would take pages of assembly language to reproduce the exact same function. The next time you're flipping through page after page of assembly language code trying to isolate a BUG, falling behind on project deadlines, and loosing all of your hair in the process, remember what you read here.. There is an easier way..

Even the hard-core assembly language programmer has a B-I-G advantage when using PicBasic Pro. PicBasic Pro allows us to use assembly language code mixed together with our BASIC code.

Example:

SERIN PortB.0, N9600, B0 ' Grab a serial byte and store it in B0 byte variable

ASM

  bsf PortB,1 ' Set bit portB.1
  bcf PortB,1 ' CLear bit portB.1

ENDASM

GOTO EXAMPLE

Or we can insert single lines of assembly code into our BASIC code using the @ symbol preceding the assembly language statements as follows:

I        VAR BYTE ' BASIC
roll     VAR BYTE ' BASIC

For I = 1 to 4     ' BASIC
   @ rlf _roll, F    ;ASSEMBLY Rotate byte left
Next I               ' BASIC

Have you ever tried a FOR NEXT loop in assembly language..? It takes a LOT of code. Even if you're using 90% assembly, PicBasic will simplify many tasks for you that would normally require hours of your time, and pages of assembly code, with a "single line" of BASIC code...

Instead of including libraries of assembly language source code to handle tasks similar to the PicBasic Pro commands such as SERIN, SEROUT, PULSOUT, PULSIN, COUNT, you can simply use the PicBasic command.

If you already have an assortment of tried & tested assembly routines - simply include them using the PicBasic in-line assembly insertion option:

@ Include "myfiles.asm"

What if...!

You want to learn assembly language programming, but you need to get the job done NOW..? PicBasic Pro helps with this as well. Using the -ol command line option with the PicBasic Pro compiler, you can tell PBP to generate an assembly .lst file at compile time. The list file can be examined or printed to see how the compiler handles converting your simple BASIC commands into assembly. This ability is an invaluable tool for the beginner trying to learn assembly language, and even the seasoned assembly language programmer looking for a few new routines or tips.

Click HERE for a sample of the conversion, and what it looks like. Some of the headers have been stripped out, but this sample is what PBP does with a simple blinking LED program.

PicBasic Pro will quickly become an important time-saving tool in even the most hard-core assembly language programmers tool-box. This degree of flexibility is rare in a compiler..

PicBasic Pro even includes commands for controlling X-10 devices throughout your house connected to your home wiring. Using XOUT to send commands to X-10 devices, and XIN to receive X-10 commands.

PicBasic Pro is not just for beginners. It first creates an assembly language file using your BASIC commands, then compiles this assembly file into a .hex file ready for burning into the PIC microcontroller directly.

Even the professional embedded design engineer will appreciate the simplicity, and huge time savings when using the PicBasic Pro compiler. You can produce the same results as someone programming in assembly or C, but in a fraction of the time.

Being a true compiler, programs execute much faster and may be considerably larger in size than their BASIC Stamp equivalents.

Simple BASIC Commands

With simple BASIC commands, PicBasic will have you programming the PIC within minutes.

The PicBasic Pro Compiler supports an large number of PIC microcontrollers.  When it comes to really saving money, this is by far the determining factor.  Take a PIC micro that costs a mere $1.76 + a single ceramic resonator, and you're ready to go -- with access to [every single I/O-pin on the PIC].

Compare using a PIC16F876 with PicBasic to the BASIC Stamp

The BASIC Stamp II 24-pin programmable module:

bullet

BASIC Stamp II cost per unit: $49.00 each

bullet

Program code size: 2K

bullet

Execution speed: 4,000 instructions per second

bullet

I/O-pins: 16. (17 if you include the programming-pin)

bullet

Interrupt capabilities: NONE

bullet

Availability of onboard PIC hardware peripherals: NONE

bullet

Adjustable speed by changing oscillators: NOPE it's fixed at 20MHz

Using PicBasic with the PIC16F876 28-pin FLASH PIC microcontroller:

bullet

20MHz PIC16F876 cost per unit: From $8.75 to $10.00 each in small quantities

bullet

Program code size: 8K

bullet

Execution speed: 5 MIPS (that's 5 million instructions per second) at 20MHz, 1 million per second at 4MHz

bullet

I/O-pins: 22

bullet

Interrupt capabilities: YES (multiple sources)

bullet

Availability of onboard hardware peripherals: YES

bullet

Timer0: 8-bit timer/counter with 8-bit prescaler

bullet

Timer1: 16-bit timer/counter with prescaler

bullet

Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler

bullet

Two Capture, Compare, PWM modules
bullet

Capture is 16-bit max. resolution is 12.5nS

bullet

Compare is 16-bit max. resolution is 200nS

bullet

PWM max resolution is 10-bit

bullet

10-bit, 5-channel, analog-to-digital converter

bullet

Synchronous serial port (SSP) with SPI (Master Mode), and I2C (Master/Slave Mode)

bullet

Universal synchronous asynchronous receiver transmitter (USART/SCI) with 9-bit address detection

Using the PicBasic compiler makes programming the PIC just as simple as a BASIC Stamp, but you have many powerful options with various PIC microcontrollers that simply aren't available with the BASIC Stamp.

The PIC16F876 can run rings around the BASIC Stamp, and costs $40.25 to $39.00 less than the BASIC Stamp II module. It doesn't take a calculator to figure out your $$ savings.

Are we knocking the BASIC Stamp..? NOT A CHANCE. The BASIC Stamp is one of the best platforms on this planet for beginners to get started programming embedded controllers. - we're just showing you the difference.

BASIC Stamp support is the best you'll find anywhere, and the Stamp itself is by far the easiest way to get started. However - using the PicBasic Pro compiler can save you considerable money should you decide to build several projects or products, and it offers the same ease of use, but much more flexibility than the Stamp.

Each time you build something with the BASIC Stamp II, you need to leave the $49.00 Stamp II module in the project for it to function. If you build more than a single project, and want to leave it all together, you'll need to invest another $49.00 [ or more ] per project when using the BASIC Stamp II modules.

bullet

Project #1 cost $49.00 (BS II module only)

bullet

Project #2 cost $49.00 (BS II module only)

bullet

Project #3 cost $49.00 (BS II module only)

Now you have three fully functional gadgets you've built, and you're leaving them all together because they're really cool, they were fun to build, and it took you a while to put them together and get everything working correctly.

You have invested $147.00 for three BS II modules (not including any other components you may need for each one). What if you decide to build 10 projects..? You're going to have to come up with $490.00 for 10 BS II modules + the cost of any extra components required for each project. 

The Stamp II modules have "NO ONBOARD HARDWARE FEATURES"; so you need to separately purchase A/D components, components for building your own PWM circuits, etc,, all at an additional cost. The PIC16F876 has many onboard hardware peripherals, and eliminates much of this cost....

If you're a company that uses the BASIC Stamp II modules in a finished product, the  price tag per-unit can add up to some rather significant amounts pretty quickly (even at large volume prices) for BS II modules, and your finished products will no doubt reflect this in your sales price to consumers.

The BASIC Stamp II an "EXCELLENT" product, and one of the easiest platforms on the planet to get started with when programming microcontrollers, but the cost per-unit is a "huge factor" when you pass the single project stage.

Now build the same three projects using a PIC16F876, and the PicBasic Pro compiler.

The PIC16F876 has 8K (instead of 2K) program code space, 22 I/O-pins (instead of 16/17), onboard hardware features that would otherwise be an "additional cost" if you're using the BASIC Stamp II (no onboard hardware features), and will execute (run) your program code at a blazing 5 million instructions (per second), compared to 4,000 with the Stamp II.

bullet

Project #1 cost $10.00

bullet

Project #2 cost $10.00

bullet

Project #3 cost $10.00

You have $30.00 invested in three projects microcontrollers + whatever external components you needed.

With the BASIC Stamp II, your cost per product or project is around $49.00 each for the Stamp II module. The PIC16F876, around $10.00 each.

What if..?

50 x BASIC Stamp II modules: $49.00 x 50 = $2,450.00
50 x PIC16F876 microcontrollers: $10.00 x 50 = $500.00

That's $1,950.00 difference, and it adds-up pretty quickly....

Both the Stamp II, and PIC16F876 prices will drop in large quantities, but the Stamp II price will never be $5.00 in any quantity. The PIC will....

Many various types of PIC microcontrollers (even in marginal quantities) are available for less than $4.00. For instance; the PIC16C63A-20/P has 4K program code space, 22 I/O-pins, operates at up to 20MHz with 5-million instructions per second, has onboard hardware features such as PWM, USART, 3 Timers, and more - yet it costs as little as $3.56 each in quantities of only 25.. You do the math....

Why is the BASIC Stamp so popular.?

The BASIC Stamp has brought programming embedded systems into the realm of the everyday hobbyist, and made getting started in programming microcontrollers S-I-M-P-L-E period..

It's easy, it's affordable to get started with, and you won't need a 4-year degree to get started. Build a better mouse trap, and they will come. Take something that used to be very complex (programming any microcontroller), make it simple to use (for everyone), and you have one of the most sought after products on the planet.

This is the "core" concept of the PicBasic compiler, but the compiler allows much more flexibility than the BASIC Stamp. It's every inch as simple to get started with, and considerably more affordable when you go beyond the single project phase. And you will once you get started... 

The PicBasic Compiler gives you full control of a multitude of PIC microcontrollers, and makes every step as simple as using the BASIC Stamp programming language - yet at a fraction of the cost.

Once you own the PicBasic Pro Compiler, you have full control of an incredible array of very inexpensive, but very powerful microcontrollers that are as simple to program as the BASIC Stamp.  The PicBasic Pro Compiler features: BASIC Stamp II commands, direct and library routine access to pins on PORTA, C, D, E, as well as PORTB, arrays, real IF..THEN..ELSE and interrupt processing in BASIC.

NOTE: New as of Sept 8, 2001, Version 2.4 of the PicBasic Pro Compiler adds several new commands.

bullet

New limited support for 12-bit core PIC microcontrollers PIC12C508 & more. Details HERE

bullet

New commands for " Dallas one-wire devices"

bullet

New support for low-speed "USB"

bullet

New special purpose 31-bit x 15-bit divide function

bullet

New command for "Hardware PWM".

bullet

New "Select Case" statements.

Current PICmicro MCU support:

PicBasic Pro Compiler now supports ALL Microchip PICmicro MCUs!

12C508(A), 12C509(A), 12CE518, 12CE519: Limited support. Details HERE

12C671, 12C672, 12CE673, 12CE674, 12F629, 12F675: Supported.

14C000: Supported.

16C432, 16C433: Supported.

16C505, 16C54(AC), 16C55(A), 16C56(A), 16C57(C), 16C58(AB), 16HV540: Limited support.

16C554, 16C557, 16C558, 16C61, 16C62(AB), 16C620(A), 16C621(A), 16C622(A), 16C63(A), 16C64(A), 16C642, 16C65(AB), 16C66, 16C662, 16C67, 16C71, 16C710, 16C711, 16C712, 16C715, 16C716, 16C717, 16C72(A), 16C73(AB), 16C74(AB), 16C745, 16C76, 16C765, 16C77, 16C770, 16C771, 16C773, 16C774, 16C781, 16C782, 16C84, 16C923, 16C924, 16C925, 16C926, 16CE623, 16CE624, 16CE625, 16F627(A), 16F628(A), 16F630, 16F648A, 16F676, 16F72, 16F73, 16F74, 16F76, 16F77, 16F818, 16F819, 16F83, 16F84(A), 16F870, 16F871, 16F872, 16F873(A), 16F874(A), 16F876(A), 16F877(A): Supported.

17C42A, 17C43, 17C44, 17C752, 17C756(A), 17C762, 17C766: Supported.

18C242, 18C442, 18C252, 18C452, 18C601, 18C658, 18C801, 18C858, 18F1220, 18F1320, 18F2220, 18F2320, 18F242, 18F248, 18F252, 18F258, 18F4220, 18F4320, 18F442, 18F448, 18F452, 18F458, 18F6620, 18F6720, 18F8620, 18F8720: Supported.

PicStic1, PicStic2, PicStic3, PicStic4, PicStic1 2k, PicStic2 2k, PicStic3 2k, PicStic4 2k, PicStic5: Supported.

The PicBasic Pro Compiler also gives you direct access to all of the PICmicro registers - I/O ports, A/D converters, hardware serial ports, internal EEPROM, etc. - easily and in BASIC.  It automatically takes care of the page boundaries and RAM banks and includes built-in commands to control intelligent LCD modules.

bullet

BASIC Stamp I and II library

bullet

True compiler provides faster program execution and longer programs than BASIC interpreters

bullet

Direct and library routine access to any pin or register

bullet

Automatic page boundary handling past 2K

bullet

Bit, byte and word arrays

bullet

Real If..Then..Else..Endif

bullet

Hierarchal expression handling

bullet

Interrupts in BASIC and assembler

bullet

Built-in LCD support. Click. HERE to see how it works.

bullet

Oscillator support from 3.58MHz to 20MHz

bullet

I2C instructions to access more external devices including serial EEPROMs

bullet

More variable space (processor dependent)

bullet

In-line assembler and Call support

bullet

MPASM / ICE compatibility

bullet

Use in DOS or Windows

bullet

Supports PIC12C67x, 12CE67x, 14C000, 16C55x, 6xx, 7xx, 84, 92x, 16CE62x, 16F62x, 8x, 87x, 17Cxxx and 18Cxxx microcontrollers

bullet

Compatible with most PICmicro programmers.

On-Chip A/D, EEPROM, Analog Comparators, PWM Modules, I2C, Hardware Serial Ports, and MORE.  There simply isn't anything else on the planet that offers this much power & flexibility for such a minimal investment...!

Take a look at the PicBasic Pro manual & see for yourself how easy PBP is to use HERE

 

The "Ultimate" File Editor/IDE for the PicBasic compilers
Click HERE to download your FREE copy now.

Click HERE to get your "PicBasic Pro Compiler"

Click HERE and check out our growing selection of complete projects & tutorials.