|
Intro to Physical Computing Syllabus code, circuits, & construction
Programming the PIC using PicBasic Pro Serial in and out (using serin2 and serout2) |
Using MELabs Loader with the PIC 16F87x |
|||
| The PIC 16F87x family of chips are capable of reprogramming themselves while running. In other words, a program resident in part of the memory of the chip can reprogram other parts of the memory. Thanks to this, it is possible to program the 16F87x PICs without a hardware programmer.
Microengineering labs makes a tool to do this called MELabs loader. Here's how it happens: You make a small program to configure the chip (set the timers, the oscillator frequency, etc.) and download it into the chip using a regular programmer like the ePIC. This program is called a bootloader, and it resides in the first 256 words of code memory. Then, you attach a serial cable to two pins of the chip (preset by the bootloader), and open up the MELabs loader program on the PC. Using MELabs loader, you load in any program you want to the chip. You can change the program, put in a new program, and so forth, as long as the bootloader is on the chip. To erase or reconfigure the bootloader, you have to go back to the ePIC and download again. For more details, see the MELabs loader page on MicroEngineering Labs' site. So how do I write this bootloader program? Actually, you don't. Microengineering Labs does. Go to their make loader page and configure it for your chip. Set the following:
Enter your email address and the form will mail you a hex file. Load this hex file into your chip using the ePIC or another programmer. When programming, make sure your options are identical to those you chose when you made the hex file on MElabs' site, and make sure you enable "Flash Program Write" in the configuration menu. This allows the bootloader to rewrite the rest of the flash program memory. Now your chip no longer needs a programmer. So how do I program the chip without a programmer? Once you've loaded the bootloader into your chip, attach a serial connector to the pins you specified when making the bootloader (RC6 for transmit to PC, RC7 for receive from PC, most likely). Put a 22K resistor in series with the receive pin, as you normally do for serial communication to the PC:
Connect the PIC to a serial port on your PC. . Before you can download a PBPro program using the bootloader, you have to make one change. Add the following to the top of your program: DEFINE ONINT_USED 1 Save this, and compile your program as usual. Now, open MELabs loader on the PC. The interface looks much like the ePIC programmer software. Make sure the serial port is set appropriately, and check "Go (run) after program" in the Options Menu. Open the hex file, and click "Program". If you get a message asking you to reset the chip, check your power and serial connections and ground the reset pin on your chip (pin 1). Then click "Program" again, and you're done. So where's the catch? Well, you lose some of the memory available for code, because the bootloader's taking it up. And you can't change the bootloader without a hardware programmer. But that's about it. In return, you gain the ability to program without a hardware programmer. It's a tradeoff that is worth making if you don't have access to a hardware programmer all the time. |
||||