Best Microcontroller Projects


XML RSS
What is this?
Add to My Yahoo!
Add to My MSN
Add to Google

Home
LCD-KEYS OnePort
C Course
Schematic Tool
PIC Introduction
PIC Programming
PIC Programmers
PIC Compilers
PIC BASIC
Tips & Techniques
PIC Tutorials
PIC Projects
Store
My SECRET
Oscilloscopes
Web Directory
MicroBlog
Problem?-Solution
Books
Wish List
Contact Me
About Me
Terms of Use
Search This Site
Freebies
Articles
Resource Links
Site Map
Your Projects
Rant/Rave
Video du Jour
Privacy Policy

I use and
recommend Firefox
for the best internet
browsing experience. Click below for your
free copy today:

CLICK THE IMAGE:


Note: I find it faster
and easier to use and
it has great plugins.  

It even imports all your current
browser settings!

There's no risk as your existing browser is not affected in any way - you can just choose which one to use.

Google

Looking for a

FREE PIC BASIC
COMPILER?


GCBASIC

It's called GCBASIC and its for PIC microcontrollers using syntax similar to QBASIC/FreeBASIC.

Find Out How This
Site Works
Like any engineering problem with the right tools it's Easy.
CLICK HERE 

Social Bookmarking
Click & Add:
add to BlinkBlink
add to Del.icio.usDel.icio.us
add to DiggDigg
add to FurlFurl
add to GoogleGoogle
add to SimpySimpy
add to SpurlSpurl
Bookmark at TechnoratiTechnorati
add to YahooY! MyWeb
Find out Why social bookmarking is
Useful For You.

Readers comments

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

SUPERB and FANTASTIC."


- Ranish Pottath


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

- Milan

bursach<at>gmail.com

Learn PIC C Now
Wondering how to program your next project using C and need a great start?


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


- Matt
matt_tr<at>
wolf359.cjb.net


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


- Dave

de_scott<at>bellsouth.net

Learn Microcontrollers
"Interested in
Microcontrollers?"


Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"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.
Regards."


- Anon





PIC BASIC 

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 of line 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 but the C language usually 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.



Don't forget to Sign Up for your

Microcontroller Newsletter

With "Essential tips and techniques",

..."New Site Info" and more...

Including a free project :

How to drive an LCD and 12key keypad using "Only One 8 Bit Port" with no interface logic!...

(Works for any microcontroller)

This costs you : Nothing...
Just fill out the form below and you'll get full C source code and project schematic and description.



Email

Name

Then

Don't worry -- your e-mail address is totally secure.
I promise to use it only to send you MicroZine.
Google
 
  Best Microcontroller projects.