Best Microcontroller Projects

Claim Your: Useful

"Arduino Software Guide"

   Right Now...



Recent Articles

  1. An Ultrasonic Distance meter project.

    Nov 25, 14 12:00 PM

    An PIC Ultrasonic Distance meter project using a PIC microcontroller which is ideal since it has a capture timer that can accurately measure the ultrasonic echo time, so calculating the distance is ea…

    Read more

  2. A dot matrix LED display project for an 8x8 or 5x7 led matrix.

    Nov 20, 14 04:58 AM

    How to drive a dot matrix LED display. This project shows you how to drive one with 64 LEDs (8 rows by 8 columns) or less e.g. 35 LEDs (7 rows by 5 columns).

    Read more

  3. USB Serial Port: How to setup an RS232 serial link through a USB port.

    Nov 20, 14 04:55 AM

    USB serial port: How to setup an RS232 serial link when you only have a USB port. There are two types of digital interfaces to consider...

    Read more

Custom Search

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:

Now



:
:
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.



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
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





Why you need a pic compiler.


What's the simplest way to programa PIC Micro? 

"Use a PIC Compiler"...

It's much easier working with a high level language (such as C or BASIC) because it uses words that are easily recognized by humans.

This typically results in a program that is much easier to write and understand.

In fact I would say that it takes about 1/10th the time to write a high level language program compared to writing the same program in assembler. This is because the complier hides the low level detail letting you get on with solving the problem.

With a pic compiler you can visually describe the program flow using tabs and spaces making it easy to see how a program works.

A good pic compiler also includes a help system for looking up elements of the language and a simulator which makes debugging the code easy.

Compiler or Interpreter ?

The other great advantage that a compiler has over interpreted language compilers is that you can get the maximum performance out of the chip. Compilers create executable hex files that run directly on the chip whereas interpreted language systems use an intermediate step and store an intermediate program either on the chip or in a separate storage device. Interpreting code from the memory takes time so you get less performance out of it.

The one advantage that the interpreted system has is that since the memory device is separate it can be made as large as required - so you can create big programs.

The fact that the interpreted language is slow is not advertised and you can tell the difference as a compiler will work with any chip but for an interpreted system you must buy a ready programmed chip - probably on a pcb. Compilers will work with any chip as long as you have a programmer.

And this brings us to the next point - If you want to create lots of projects then for a compiler you have a one time non recurring cost - the compiler itself. But for an interpreted system you must keep buying the pcb and support chips - so your projects will cost a lot more to make.

What is a pic compiler ?

A pic compiler (or any compiler) is a program that translates one computer program into another. Source code written in a high level language is translated into machine code that the microcontroller understands. This simplifies the task since you do not have to write assembler - you are only concentrating on the high level language.

Here is an example of a 'C' program and its assembler output i.e. the (machine code) output of the pic compiler :

Example output

Example high level 'C' language source code for a pic compiler:

   void main() {
   PORTB = 0;
   TRISB = 0;
       
       do {
           switch (PORTB) {
               case 0x00: PORTB = 0xFF; break;
               case 0xFF: PORTB = 0x00;
           }
           Delay_ms(1000);
       } while (1);
   }

Output generated by the compiler i.e. machine code (and assembler) :

This following text is quite long please scroll down to past it to see comments about it and continue.

; ADDRESS    OPCODE  ASM                         
; ---------------------------------------------- 
$0000        $2804   GOTO    _main       
$0004        $       _main:              
$0004        $1303   BCF     STATUS,RP1  
$0005        $1283   BCF     STATUS,RP0  
$0006        $0186   CLRF    PORTB       
$0007        $1683   BSF     STATUS,RP0  
$0008        $0186   CLRF    TRISB       
$0009        $       L_main_0:           
$0009        $1303   BCF     STATUS,RP1  
$000A        $1683   BSF     STATUS,RP0  
$000B        $2812   GOTO    L_main_2    
$000C        $       L_main_4:           
$000C        $30FF   MOVLW   255         
$000D        $1283   BCF     STATUS,RP0  
$000E        $0086   MOVWF   PORTB       
$000F        $281F   GOTO    L_main_3    
$0010        $       L_main_5:           
$0010        $0186   CLRF    PORTB       
$0011        $281F   GOTO    L_main_3    
$0012        $       L_main_2:           
$0012        $1303   BCF     STATUS,RP1  
$0013        $1283   BCF     STATUS,RP0  
$0014        $01F0   CLRF    STACK_0     
$0015        $0870   MOVF    STACK_0,W   
$0016        $0206   SUBWF   PORTB,W     
$0017        $1903   BTFSC   STATUS,Z    
$0018        $280C   GOTO    L_main_4    
$0019        $30FF   MOVLW   255         
$001A        $00F0   MOVWF   STACK_0     
$001B        $0870   MOVF    STACK_0,W   
$001C        $0206   SUBWF   PORTB,W     
$001D        $1903   BTFSC   STATUS,Z    
$001E        $2810   GOTO    L_main_5    
$001F        $       L_main_3:           
$001F        $300B   MOVLW   11          
$0020        $00F0   MOVWF   STACK_0     
$0021        $30FF   MOVLW   255         
$0022        $00F1   MOVWF   STACK_1     
$0023        $30FF   MOVLW   255         
$0024        $00F2   MOVWF   STACK_2     
$0025        $0BF0   DECFSZ  STACK_0,F   
$0026        $2828   GOTO    $+2         
$0027        $282F   GOTO    $+8         
$0028        $0BF1   DECFSZ  STACK_1,F   
$0029        $282B   GOTO    $+2         
$002A        $282E   GOTO    $+4         
$002B        $0BF2   DECFSZ  STACK_2,F   
$002C        $282B   GOTO    $-1         
$002D        $2828   GOTO    $-5         
$002E        $2825   GOTO    $-9         
$002F        $3033   MOVLW   51          
$0030        $00F3   MOVWF   STACK_3     
$0031        $30FF   MOVLW   255         
$0032        $00F4   MOVWF   STACK_4     
$0033        $0BF3   DECFSZ  STACK_3,F   
$0034        $2836   GOTO    $+2         
$0035        $2839   GOTO    $+4         
$0036        $0BF4   DECFSZ  STACK_4,F   
$0037        $2836   GOTO    $-1         
$0038        $2833   GOTO    $-5         
$0039        $3088   MOVLW   136         
$003A        $00F5   MOVWF   STACK_5     
$003B        $0BF5   DECFSZ  STACK_5,F   
$003C        $283B   GOTO    $-1         
$003D        $0000   nop                 
$003E        $0000   nop                 
$003F        $2809   GOTO    L_main_0    
$0040        $       L_main_1:           
$0040        $2840   GOTO    $

This shows you how much easier
it is using a compiled language over
raw assembler.

The second column is the actual machine code that the microcontroller reads (opcode) while the third and fourth are the assembler translation (a bit more readable than the opcode).

As you can see the source code is much more compact than the assembler output and is far more readable. You can also see that it is doing something with PORTB and there is a delay included whereas with the machine code you can't really tell what is going on and there are a lot more lines of code to work through.

Of course comments are (hopefully) included for hand written assembler but there are still the same number of statements to understand.

What is the advantage of a pic compiler ?

The compiler's language lets you...

  • Code applications more quickly - less lines of code than assembler.
  • Write programs that are easier to understand.
  • Use ready made libraries - you don't need to write as much code.
  • Concentrate on the task - it manages low level hardware details.
  • Use the same source code for different target micros.
  • Work only in the high level language - no need for assembler.
  • Read the code easily (see layout of the example above).
  • Program different microcontrollers in the same family e.g. PIC.
  • Learn a standard language such as C to use in a profession.

A good pic compiler will also let you...

  • Simulate the source code - no need for assembler.
  • View procedure memory usage showing the effect of code changes.

Types of pic compiler

There are two main languages used for pic microcontroller programming BASIC and C. These are by far the most popular languages and there are many compilers with varying cost/performance ratios. Other less popular pic compilers are PASCAL, FORTH and JAL.

High level language compilers available for the PIC Micro:

  • C The most widely used programming language.
  • BASIC Beginners All Purpose Symbolic Instruction Code.
  • PASCAL Based on ALGOL and named in honor of Blaise Pascal.
  • FORTH by Chuck Moore named as suitable for fourth generation computers.
  • JAL Just Another Language by Wouter van Ooijen (PASCAL based).

Key features:

ANSI standardized

  • C has an ANSI standard, lots of code available, Widely used.
  • PASCAL has an ANSI standard, lots of code available, Widely used.
  • FORTH has an ANSI standard.
  • BASIC Major drawback - it doesn't follow a standard.
  • JAL No standard - but there is only one compiler so it does not matter.

Having an ANSI standard associated with a language means that any pic compiler can be used to compile the source code - and the compiler will accept that source code regardless of the target micro family. Note you may have to make some adjustments e.g. register names, hardware operation etc.

It is a problem for BASIC as there is no standard - so if you write BASIC source code using one compiler it most likely will not work if you use a different compiler.

Ease of use

  • C easy - difficult.
  • PASCAL easy - difficult.
  • FORTH very difficult.
  • BASIC easy.
  • JAL easy.

Main benefit:

  • C Can access low level hardware, structured layout.
  • PASCAL Easy to write, structured layout.
  • FORTH compact code, and very fast - not as structured as above.
  • BASIC Easy to write, can be structured depending on compiler.
  • JAL based on Pascal, structured layout.

Main Disadvantage:

  • C Depending on how it is written can be extremely cryptic.
  • PASCAL Lengthy to write and distinguishes between procedures/Functions.
  • FORTH Uses Reverse Polish Notation and code is very difficult to read.
  • BASIC Does not follow a standard.
  • JAL Only one compiler - no other choice i.e. no support.

Availability for pic micro:

  • C A large number of compilers are available.
  • PASCAL Only one or two compilers available.
  • FORTH A few compilers available.
  • BASIC A large number of compilers are available.
  • JAL Only one compiler available.

What to look for in a compiler.

When starting out you should use a pic compiler that has a text editor and simulator built in known as an IDE (Integrated Development Environment).

A good help system will give examples of the language which saves getting a text book out (Some help files also have examples of typical hardware solutions).

Obviously cost is a consideration - the best are going to cost more. However you can use some that are very low cost and perform well.


Jump from pic compiler page to
Best-Microcontroller-Projects Home Page

Privacy Policy | Contact | About Me

Site Map | Terms of Use | Links




Google
 
  Best Microcontroller projects.