How to Relocate User Code

User code must be relocated at address 0x0200 or 0x0800 depending on the model and firmware used. The start of user space depends on the size of the boot block. Originally, the boot block for PIC18F devices was 256 bytes. Lately, most new models have a boot block of 1024 bytes. To determine the size of the boot block for your device, you may look at the PicDevices.properties file.

If you are not concerned about protecting the boot block, you can still relocate the user code to address 0x0200 even if your device boot block is 1024 bytes, but you must change the appropriate entry in the PicDevices.properties file and you must use the appropriate bootloader firmware (bootloader.hex).

CCS

Add the following directives in you .c file:

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
nop
#endasm
} // Reserve space for the bootloader

SDCC

Use the compiler directive --ivt-loc 0x200.

HI-TECH PICC

In the link phase, use the linker directive -a200h.

Microchip C18

Edit the Linker script 18f452_c.lkr to protect the boot block, and rebuild the C18 startup objects c018.o and c018i.o. Also be certain you have not defined absolute code sections in the source code to start in the boot block. For instance:

#pragma code InterruptVectorHigh = 0x08

must be changed to

#pragma code InterruptVectorHigh = 0x208

PIC is a registered trademark of Microchip Technology Inc.