IE Mysteriously not allowing cookies Adobe apollo / air

Hardware Programming! The picKit2 from Microchip

13 Apr 2007

So I've wanted to learn some hardware programming for quite a while, and have now taken the first step!

A popular choice of learning resources is the company , they have a product called the picKit 2, which is a 'demo board' . After much reading i understand that this is a circuit designed to help you get up and running quickly.

In the case of the pickit2, this means it has a processor on board ( the pic16f917 ) , a bunch of led's already wired in , a potentiometer (turny switch) and a button.. as well as a bunch of open outputs for you to do whatever you like with.

This is not something for the faint of heart it would appear, so after stumbling around the documentation and sample code for a while, i bought this book The Pic Microcontroller, your personal introductory course, a promising name.

The book is very well written, and after the first 2 chapters i felt much more able to approach my board.

The demo board comes with a usb device that attaches it to the computer, i've learned that this is a 'programmer' , which is in charge of delivering the compiled code to the chip itself, the integration of this is one of the things that makes this a 'demo' board.

After some more reading, i tried out my first program, borrowing some sample code from one of the existing projects, I had success!

See here my first program running, in all it's glorious 7 lights on, 1 light off glory!


Functionally, every 8 outputs get assigned a file register (memory location), and by assigning an 8 bit binary value to this location, you can set the pins as either on, or off. So to set the first pin on, you use a value of 00000001 , the first and last as 10000001, etc... The default numbering system in assembly is hexidecimal, so you represent these as hex, so, 00000001 = 1, 10000001 = 81.

Here is the functional element to my program, which turned all pins on, except for the 2nd pin.

MainLoop movlw 0xfd movwf PORTD

goto    MainLoop

so, as you can see here I am using the hex value fd, and assigning it to the file page that controls my led's. fd of course equals 253 in decimal, or 11111101 in binary, so you can see the led that's off. The other commands are pretty simple as well mov = mov l = literal w = working register (you only get one of these, everything moves through it) f = file page

so movlw 0xfd means, move a literal into the working register, and then i give the literal 0xfd , 0x just means its a hex number. I could aslo have used movlw b'11111101 , or for that matter movlw d'253

and then movwf PORTD means, move the working register into the filepage PORTD (my output register).

Really pretty simple at the end of the day, once your environment is running.