|
Intro to Physical Computing Syllabus code, circuits, & construction
|
Programming the PIC: PicBasic Pro Step-by-Step |
|||
In this example, we'll program a PIC 18F452 to blink an LED on pin D1 using PicBasic Pro and an EPIC programmer. If you're using a different model PIC, change the pin number to one that'a actually on your PIC. This small program makes RD1 an output and turns it on and off:
' make RD1 an output: output PORTD.1 main: high PORTD.1 pause 500 ' pause 500 msec. low PORTD.1 pause 500 goto main |
||||
| To put this program on the PIC, do as follows:
Attach the EPIC Plus programmer to the parallel port of the PC, and make sure its powered. Open MicroCode studio, and enter the text above. Click the Compile and Program button, and MicroCode Studio will call PicBasic Pro and MPASMWIN to compile the program. These will produce a number of files, all with the same name and different extensions, like the BasicX software did for the BX-24. The file with the extension .bas contains your text, and the file with the extension .hex is the one that will be downloaded to the chip.
Once the compiling is done, MicroCode Studio will open the EPIC Plus software to prepare for download. It will look like this: Its up to you to complete the download. First, attach the 40-pin ZIF adaptor to the EPIC programmer like this:
Next, insert the PIC into the socket with the top next to the lever. Press the lever down to hold the PIC in the socket:
Go to the View menu of the EPIC software and choose Configuration. This menu allows you to set various characteristics of the PIC, such as the type of clock crystal you are using (for our examples, choose XT for a 4Mhz crystal, and HS for a 20Mhz crystal), which timers in the PIC are turned on or off, and so forth.
For this example, set the clock to XT and leave the rest alone. Then click the program button and the software will download your program to the PIC. Put the PIC back into its circuit, power it up, and your LED should blink. |
||||