/ Hathaway Weblog / Programming a PIC Microcontroller

Shane :: Life :: October 25, 2005 # Programming a PIC Microcontroller

I decided earlier this month to build a toy for my kids. It's somewhat fortunate that they can't read yet, since that means I can talk about the toy freely in my weblog. :-)

I plan to build a race course for a pair of radio controlled cars. The cars will pass through checkpoints with sensors and lights. The checkpoints will be connected to a base station that monitors the checkpoints and says things like "now go to checkpoint four!" The base station will have buttons that let you select different games like Follow the Leader, Simon Says, Quick Dash, Fast Laps, etc. It will all be put together with wood and simple circuit boards.

So far, everything is going well. This is the first time I've used microcontrollers and surface mount devices. I've connected a 128MB SD card to a 20 MHz PIC16F819, using the SPI interface. The PIC reads from the card and outputs 8 bit audio samples to a D/A converter, which feeds to an audio amplifier. After a lot of debugging (it was hard to eliminate humming and static), the music finally came through clearly--at a full 44KHz! Well, as clearly as 8 bit samples can be. I think I would use 16 bit samples if I were building more than one of these gadgets.

So now I'm really happy with the PIC. It's cheap and can actually handle 44,000 interrupts per second. They're quirky, though! For example, I had to familiarize myself deeply with the entire datasheet before I discovered that I could not use one of the pins for I/O unless I disabled LVP (low voltage programming) mode. However, now that I understand that, I can apply it to any PIC.

To program the PIC, I first tried an old Picstart Plus I bought years ago (but never tried until now). The device turned out to be too old to program the chip I bought, so I looked for the least expensive way to get a reliable programmer. Based on advice I found at the PIKDev web site, I bought the PIC-PG3B parallel port programmer from Spark Fun.

PIKDev is compatible with this programmer. Under Linux, I had to compile the "ppdev" kernel module (I presume it's required for raw parallel port access) and "modprobe ppdev; chgrp shane /dev/parport0; chmod g+rw /dev/parport0" before running PIKDev. Then I selected the Tait 7405/7406 programmer configuration.

The programmer requires a separate 15-18V supply for programming, so I first tried a pair of 9V batteries in series. This worked for one day, but the next day I couldn't get it to work again. It would program fine, but failed verification. Then I discovered, to my astonishment, that my laptop's power supply outputs 16V and uses the exact plug required by the programmer. That solved the voltage problem, but the programmer still failed intermittently. Once I put a basic grounding shield (a piece of foam) under the programmer, it finally worked well.

So far, I've been using CC5X to generate assembly code, but the free version of CC5X is limited. I think I'll try JAL next. I've already been through dozens of languages--why not yet another?

Comments

nazemi (October 19, 2006 14:17)

dear ... pleas send me some practical sourses project from this pic tanks for your co operation

No further comments may be added.

Alma 34:32-34 (Click below to fill in the blanks.)
Your browser is not able to display the scripture fill-in program. To see it, enable Javascript or use Mozilla 1.0 or better.

Church: lds scriptures provident games pearls kzion shiblon film chancellor gateway cumorah byutv happiness nephi
Zope: freezope org com zen labs newbies zettai warnes
Python: home pyzine daily icanprogram
Genealogy: cyndi
Weblogs: jeffrey paul jon joel another-shane guido barry jeremy windley chrism zac
News: quakes lwn dc weather deseret zeitgeist softwarelivre
Zaurus: software developer
Tech: tango spintronics thin
Semantic: aaron sean
Reference: css rdf html4 javascript geckodom iecss emacs phrases acronyms
Reverse: advogato slashdot
Misc: gimp-savvy directory soda jokes shouldexist pdphoto