You’re probably thinking of a PIC that has a ‘bootloader’ already burned into it.
Here’s a rundown of PIC programming:
To get code into a raw PIC, you hook up to five signals: MCLR, CLK, DATA, Vdd, and Vss. MCLR is the PIC’s reset line. CLK and DATA are pins that are also I/O pins when you’re not programming it. [There is a variation that involves a sixth pin, but I’m skipping over it…].
A PIC programmer applies about 13V to MCLR, which informs the PIC that it is being programmed. The programmer sends something to the PIC to cause it to erase it’s Flash memory. Then the programmer sends data serially to the PIC via the CLK and DATA lines, and the data gets burned into Flash and/or EEPROM. When the programmer releases MCLR (back to 5V), then the PIC inits itself and starts running code at address 0000.
But some folks have their PIC installed in a board where there is no good way to hook up the programmer to the required pins. If the board has any sort of data interface to the outside world (serial, parallel, whatever), then it is possible to use a ‘bootloader’.
What this means is that before you install the PIC in the board you use a conventional PIC programmer (as described above) to burn a small program into the PIC. The purpose of this program is to use the existing interface (RS232, for example) to receive data that needs to be burned into the PIC, and then to burn that data into Flash, but without erasing or modifying the bootloader code that is already there.
As an example, a bootloader that I wrote works like this:
- The bootloader code lives at address 0000 thru 0300.
- When the PIC powers up, the bootloader code runs by default (from address 0000).
- The bootloader does bare-minimum initialization, including setting up I2C.
- The bootloader waits for about 1 second to see if it can receive anything on the I2C bus.
- If nothing is received within 1 second, the bootloader branches to address 0300, which is assumed to be the user’s code, and the PIC does it’s normal thing.
- If the bootloader gets something via I2C, it assumes that it is one of 2 possible commands: Erase Flash or Program Flash.
- If the command is Erase, the bootloader erases everything from 0300 to the top of memory.
- If the command is Program, then the bootloader receives bytes and burns them into Flash, from 0300 on up.
- After the ‘host’ sends all the bytes, it resets the PIC, waits 1 second, then the PIC should be running the new code…
On my board, I put 5-pin programming headers on the board, so it is easy to program the PICs in-circuit. [For the dsPIC, 2 jumpers have to be removed during programming, because those pins are shared with I2C, and the programmer doesn’t like seeing the pullup Rs on the signals.]
A bootloader is a bit of hassle to set up, so I don’t plan to do it with this board. There are free bootloaders on the web, but be aware that they typically only work with certain PICs, because they must deal with interrupt vectors and such.
If you have a robot with a wireless link, then a bootloader would be a cool way to do code updates remotely.
Pete