News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Microchip PIC and similar microcontrollers

Started by Mark Jones, February 01, 2006, 11:18:04 PM

Previous topic - Next topic

Mark Jones

There's been talk over the years about PICs and microcontrollers, so here is a short Q&A.

What is a microcontroller?
A microcontroller (µC) is an electronic integrated circuit which has many of the same characteristics of larger processors like the x86. A µC typically has a small amount of RAM, one or more registers, some EEPROM to store the actual program in, a tiny bit of EEPROM for storing non-volatile data, and variety of I/O ports. Some models include various other I/O features such as analog input, A/D, comparitor input, PWM output, etc. Some higher models even include USB, Laser Optical, and/or Firewire support.

What can a microcontroller do?
A microcontroller is a very special form of hardware which behaves like an electronic "brain." Traditionally in electronics, complex digial logic meant either boards and boards of discrete chips and a nightmarish tree of logic gates to sort through, or big bucks for a manufacturer to make custom chips for you. But today, a small µC can do the same thing as those boards of chips and more. Furthermore the µC incorporates related electronic functions in the chip itself such as analog-to-digital conversion, PWM output, etc. This cuts down on other circuitry which you might have to build.

Is a lot of electronics knowlege required to design microcontroller applications?
Kind-of. Microcontrollers are complex electronic devices. Most of their topology is steady-state digital logic which isn't too hard but some of the analog electronics specifics can get technical. It might be feasible to be just a µC programmer and let someone else handle the hardware, but thit is not realistic because most of the program instructions deal directly with pins and electrical signals.

Can I see some code?
Sure. This is a code snippet from a PIC16F series. The hardware is wired to blink a light on the second pin of "PORT A."

;*****Set up the Constants****

    STATUS  equ 03h         ;Address of the STATUS register
    TRISA   equ 85h         ;Address of the tristate register for port A
    PORTA   equ 05h         ;Address of Port A
    COUNT1  equ 08h         ;Address of first counter
    COUNT2  equ 09h         ;Address of second counter

;****Set up the port****

    bsf     STATUS,5        ;Switch to Bank 1
    movlw   00h             ;Set the Port A pins
    movwf   TRISA           ;to output.
    bcf     STATUS,5        ;Switch back to Bank 0

;****Turn the LED on****

Start
    movlw   02h             ;Turn the LED on by first putting it
    movwf   PORTA           ;into the w register and then on the port

;****Start of the delay loop 1****

Loop1
    decfsz  COUNT1,1        ;Subtract 1 from 255
    goto    Loop1           ;If COUNT is zero, carry on.
    decfsz  COUNT2,1        ;Subtract 1 from 255
    goto    Loop1           ;Go back to the start of our loop.
                            ;This delay counts down from 255 to zero, 255 times

;****Delay finished, now turn the LED off****
    movlw   00h             ;Turn the LED off by first putting
    movwf   PORTA           ;it into the w register and then on the port

;****Add another delay****

Loop2
    decfsz  COUNT1,1        ;This second loop keeps the
    goto    Loop2           ;LED turned off long enough for
    decfsz  COUNT2,1        ;us to see it turned off
    goto    Loop2           ;

;****Now go back to the start of the program

    goto    Start           ;go back to Start and turn LED on again

;****End of the program****

end


Hmm. How much do microcontrollers cost?
Surprisingly, very little. Typically between $2 to $10 USD for average mid-range devices. The high-speed powerhouses can cost $20 or more.

That's cheap! I'm sold! How do I get started?
Whoa, not so fast! Some things tend to sound good on paper but be difficult in practice. To program a µC you'll need the following:
1. A microcontroller programmer.
2. A free serial/parallel/usb port - no routers, no switches... a dedicated port.
3. Programming software.
4. Assembly / Compiler / IDE software.

Furthermore, you'll also need:
5. A prototyping board or means of testing your completed project.
6. An applicable power source.
7. A handful of electronic parts to use while supporting and designing the project.

Now depending on which variety of µC you buy, this may be an easy & cheap affair or a difficult & costly one. The laws of trines apply, pick any two:  __Ease of Use  __Affordability  __Features. Probably the most important thing you can do is to research the different brands of µC and make a decision based on the features which will benefit you the most.

Cool, I'll get the biggest, most cutting-edge microcontroller I can buy then.
Don't! It may be tempting but trust me, µCs have a tendency of getting really complex, really fast. Bigger chips only cause more confusion to a newcomer. Your best bet is to get a small or midrange µC with lots of ram and code space but not all the bloated features. Learn that exhaustively then move up to the large µCs if need be. The old chip can be retired to blink lights on your desk or play the star wars theme, as a token of your completion like a diploma.

So how much does this cost altogether?
Well, some have found free tools and botched together a few wires and resistors to program µC's, while others insist on using the expensive developer tools costing thousands - it's really up to you. I took the middle road and bought a multi-function µC programmer, a nice breadboard, a small power supply, and a big box of assorted electronic components from eBay. Total expense, probably about $200.

Well I'll think about it... got any links?
Sure. Here's a two pages which list the top µC manufacturers plus a whole lot more:
http://www.neatsite.com/micros.htm
http://microcontroller.com/EmbeddedSystems.asp?c=9

Yahoo and Google Groups is a great place to learn about microcontrollers:
PIC Google Group: http://groups.google.com/group/PIC-Discussion
JAL Yahoo Group: http://groups.yahoo.com/group/jallist/
AVR Google Group: http://groups.google.com/group/Atmel-AVR

This is a great multi-function programmer. Can you find my two contributions?
http://www.picallw.com/
Economy programmer, bootloader, etc.
http://www.voti.nl/wisp628/

Here are sites with tutorials and lots of good info:
http://robotag.carleton.ca/resources/technical/pic_introduction.shtml
http://www.mstracey.btinternet.co.uk/pictutorial/picmain.htm
http://www.voti.nl/pic/index.html
http://members.home.nl/b.vandam/lonely/index.html

PicMicro Webring:
http://o.webring.com/webring?ring=picmicro;list

Projects, ideas, etc:
http://www.quasarelectronics.com/microcontroller_projects.htm
http://www.rentron.com/pic.htm
http://www.oopic.com/
http://www.trash.net/~luethi/microchip/projects/projects.html
http://www.commlinx.com.au/microcontroller.htm
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08