Thursday, August 09, 2007

PICKIT 2 Programming

I finally got my hands on a decent PIC programmer, and have finally gotten it working. Surprisingly I had more trouble with the compiling of programs than I did with hooking it up physically. The first is figuring out the header files to use, I've always been using p18cxxx.h(For the pic18F chips) and delays.h(This is just for adding waits) which are both needed for any sort of toy programs. The main problem though was pragmas, which took me a while to figure out. The three that I've always been using since it's been working are:
#pragma config WDT = OFF // No clue, but always needed
#pragma config OSC = HS // Use external oscillator

#pragma config LVP = OFF // Turn off LVP Programming


My toy program is a simple LED chaser that goes back and forth and gets progressively faster until it goes so fast it's just flashing all of the LEDs. The source can be found here.

Here's a picture of the breadboard...really only 5 of the LEDs and the microcontroller are used to run it, as well as the oscillator, the rest is just other tinkering. I just left the pickit2 plugged in since I was reprogramming it alot, except I've always been having to swap the voltage on the pickit2 with the voltage on the breadboard:



1 comment:

Phlogiston said...

The "pragma config WDT = OFF" is required to turn the watchdog timer off. Othwerwise, the watchdog will reset the chip every few seconds or so, because its timer runs out. This can be a useful feature to prevent programs from locking up.