Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine.


Beginners All Purpose Symbolic Instruction Code for PICS. 

BASIC is a good choice 
when you are
starting out...

BASIC is the simplest language and must not be dismissed because it is old.  It's true it has some limitations (modern compilers do not have many limitations) but it is excellent when you are starting out...

There's even a free one called GCBASIC.

BASIC was the first language that I ever used and PIC BASIC is BASIC optimized for the PIC Micro. OK I'll date myself a bit here - MZ80K, Spectrum, Amstrad - the heady days of the Z80 based computer which all used BASIC.

BASIC has improved over the years getting rid ofline number based listing and using the procedure based method common to other languages.

This fact alone makes PIC BASIC much easier to use e.g. instead of GOSUB 9810 (a line number) you can use GOSUB abc where abc is the name of a subroutine.

But it has not changed that much and this explains its popularity - you can use the BASIC that you learnt years ago and program advanced PIC Micros.

There are several PIC BASIC systems and these are either interpreter or compiler based.

Jump to Interpreted or Compiled ?

Jump to InterpreterPros, Cons.

Jump to CompilerPros, Cons.

If you are new to programming, PIC BASIC is also a very easy introduction to microcontroller programming as the language is not difficult to master.

I expect that later on you can move onto other languages as the only disadvantage of PIC BASIC is that sometimes, for advanced programming, it limits what you can do.

In the past at work I have been asked to program in an ancient version of BASIC and it is extremely frustrating as you tend to rely on the features of the program i.e. you start programming because it claims to be able to do something.  Once you get there you find you would like to add a tiny extra operation and you can not!  There is simply not enough functionality in the functions provided and you can not add any more.  

C tends to let you do more as most of the functions are themselves written in C - this basically means that if a function is not available you just write it yourself.

This is why the 'C' language is so popular you can do virtually anything you need to do in 'C'.  Also you can structure the program more easily and this lets you more easily understand how the program works but PIC BASIC is still powerful and modern versions let you do much more - even adding your own assembler code.

Note: Even with advanced programming limitations you can still do an enormous amount using PIC BASIC.

Sidebar : GOTO

Note: Use of GOTO is not considered good programming practice.

The reason is that when you use it you have no way of getting back to where you started.  The program's flow is completely disrupted and you are dependent on the routine that you are in to get you to the next program operation.  (This is ok for a small test program but hopeless for anything large).  

You need to use GOSUB - better to just not use GOTO at all.  A procedure that you have called using GOSUB will let you go back to the caller at any time using RETURN.  This method is equivalent to procedure/function calls in all other languages (Yes C does have a goto statement but everyone avoids it at all cost).

Using subroutines structures your code for easy reading and maintenance as you can use your main procedure at the top level - if you think of your program as a root system that branches down.  Each branch represents a single subroutine and side branches off of these represent more subroutines.

PIC BASIC : Interpreted or compiled - What is the difference ?

There are two flavors of BASIC for PIC Micros:

  • Interpreted PIC BASIC
  • Compiled PIC BASIC

Here's a comparison between Interpreted and Compiled PIC BASIC :

PIC BASIC Type Interpreted  Compiled
Output Tokens Hex file
Speed Slow Fast
Ease of use Very easy. More difficult.
Executer Size Depends. Zero
Program Size Should be expandable to any size (if using external eeprom). Limited to microcontroller internal memory size.
Cost High (if doing lots of projects) Low (if doing lots of projects)
Examples picaxe, Basic Stamp PICBasic, MikroBasic

Interpreted PIC BASIC

An interpreted language uses a controlling program to read a set of tokens and translate these tokens into machine code on-the-fly.  As each token is interpreted the machine code is executed.

For each instruction e.g. FOR, RETURN, GOSUB etc. a unique code is assigned
to the token - this is simply a number.  These are read from memory and interpreted sequentially.

Note: Special methods are used to distinguish between 'Tokens' and a number e.g. a WORD.

The key points here are :

  • controlling program.
  • on-the-fly.
  • ease of use.

Interpreted PIC BASIC : Controlling program

The interpreter is a controlling program that interprets the tokens and it has to be present in the microcontroller and it will be quite large - so you loose some of the internal program memory of the PIC.  

The amount of memory you loose depends on the commands supported and in some cases this does not matter as the tokens are loaded into a separate external memory (serial eeprom) while in others only internal memory is used .

Interpreted PIC BASIC : On-the-fly

The process of interpreting a token takes the following steps:

  1. Get token from the memory store (could be external serial EEPROM).
  2. Translate to machine code (stored within the interpreter).
  3. Jump to and execute the interpreter code.
  4. Return to fetch the next token.

The important point is that there are many steps and each one takes time so with an interpreted basic you will never be able to drive it as fast as using assembler (machine code) or using a compiled language.

Interpreted PIC BASIC : Ease of use

The saving grace for a BASIC interpreter is that it is easy to use and the one feature that gives it an edge over a compiler based language is:  

You only need a serial cable to program it (e.g. picaxe).

They work using the PIC feature of self programming where the PIC can write to its own internal (Flash) program memory (not the EEPROM).  

Note: This is effectively a bootloader with added 'BASIC' functions.  It bootloads the program into internal memory or I2C serial EEPROM and executes it.

Interpreted PIC BASIC : Disadvantage ?

Its slow and in the long run it costs you more.

Also some features may not be available e.g. interrupts - you need to carefully check the documentation before buying it.

Note: picaxe may be an exception as it is priced a little bit more than the cost of the chip (ok it still costs more than the chip).

Interpreted PIC BASIC : Advantage ?

A PIC BASIC interpreter is the easiest way to start programming with microcontrollers.

Compiled PIC BASIC

A PIC BASIC compiler, although the front end tools look virtually identical to a PIC BASIC interpreter, outputs either assembler code or a hex file that you can directly load into your PIC Micro.  There are no tokens and no intermediate steps so you can drive the Microcontroller at the fastest possible speed fetching instructions from internal memory and executing them immediately.

The compiler directly outputs executable code.

The compiler is the favored method of program generation in industry as it gives you complete control over the microcontroller butthe Clanguageusually used.

PIC BASIC Compiler : Disadvantage ?

Separate programmer and programming software running on the PC.  

This adds more complexity to programming the chip. i.e. you have either a serial or parallel cable (or USB) to the programmer circuit and then an ICSP connector to your target board and you use PC programming software to stuff the data into the microcontroller.  

Note: There is a way around this - by using a bootloader - this consumes a small amount of internal memory (but is not as big as the interpreter). But you still need a programmer to get the bootloader into the Micro in the first place - this is what you buy when you buy a BS2 or picaxe i.e. a bootloader and interpreter combined.

PIC BASIC Compiler : Advantage ?

A PIC BASIC compiler gives the maximum speed and best use of internal program memory and resources.

Also, once you have bought the compiler you do not need to buy any other module (usually a costly component) you just buy the raw microcontroller chip.

Note: Costs can mount up if you use interpreted BASIC modules. e.g. if an interpreter module costs $50 each and you do ten projects it will cost $500 (just for the module).  If you buy a compiler $200 say and do ten projects (with a $10 microcontroller) then you spend a total of $300.  So if you intend to do a lot of project work it's worth investing in a good compiler (but check picaxe price).

There's a free open source PIC BASIC compiler here.

Jump from PIC BASIC page to
Best-Microcontroller-Projects Home Page.

New! Comments

Have your say about what you just read! Leave me a comment in the box below.

Claim Your: Useful

"Arduino Software Guide"

   Right Now...

Privacy Policy | Contact | About Me

Site Map | Terms of Use

Visit our Facebook Page:

   Click Here

Sign up for MicroZine
''The'' Microcontroller Newsletter

Enter your first Name and primary email address in the form below:

And receive absolutely FREE a full project for:

"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be  Removed 
at any time.  

It will  NOT be 
available indefinitely SO
To avoid 
disappointment  get it:


Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.

To get exclusive access Enter your first name Name and primary email address Now in the form above.:

But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates

Scroll up to the form above and sign up NOW. Don't forget it's FREE and if you don't like it, you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's


- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan


"Awesome site,
very, very easy and nice
to navigate!"

- Matt

Learn Microcontrollers

"Interested in

Sign up for The
Free 7 day guide:


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."

- Dave


"Your site is a great
and perfect work.

- Suresh


"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.

- Anon

Recent Articles

  1. Eye Tracking System

    Eye tracking : How to detect the gaze of your eye and track where you are looking.

    Read more

  2. DS18B20: How to use it on the Arduino Uno.

    How to Easily Use the DS18B20 Maxim One-Wire thermometer with Arduino example code using both external powered and parasitic powered devices.

    Read more

  3. The best Microcontroller projects and resources.

    Do you want to learn how to use a microcontroller in your electronic projects or do you need inspiration for your next project? If so you have found the right place!

    Read more