Bootloader for 18LF25K50

As I promised some weeks ago, I'm sharing with you the bootloader for this pic, adapted to development board I'm working with. There are some highlights on this bootloader:

  • It is based on Microchip Application Libraries, which provides a generic bootloader for 18F devices.
  • In this case I adapted it to avoid using blinking LEDs and be able to distinguish between bootloader mode or normal execution. As you can see in the schematic, I use the RC2 pin to check it.
  • I used free version of C18 compiler and it has no optimization when compiling so the bootloader uses more than 0x1000 memory addresses so I changed all pointers for reset and interruptions. Final flash memory usage uses 0x1102, I'm trying to delete unused code in order to reduce it below 0x1000 to match with the general version.

This is the code I want to remark:

Vectors remapping:


Bootloader main code:

//Assuming the I/O pin check entry method is enabled, check the I/O pin value
//to see if we should stay in bootloader mode, or jump to normal applicaiton
//execution mode.


//Need to make sure the I/O pin is configured for digital mode so we
//can sense the digital level on the input pin.


//Check Bootload Mode Entry Condition from the I/O pin (ex: place a
//pushbutton and pull up resistor on the pin)

if(sw2 == 1) {
    goto REMAPPED_APPLICATION_RESET_VECTOR //If the user is not trying to enter the bootloader, go straight to the main application remapped "reset" vector.

  //If we get to here, the user is not pressing the pushbutton. We
  //should default to jumping into application run mode in this case.
  //Restore default "reset" value of registers we may have modified temporarily.

  //Before going to application image however, make sure the image
  //is properly signed and is intact.
  //goto DoFlashSignatureCheck;

} else {
  //User is pressing the pushbutton. We should stay in bootloader mode
  _asm goto BootMain _endasm


 You have Mplabx project at the bottom of this entry. Feel free to get in contact with me if you have any doubts.

Download Bootloader 28LF25K50


MPLAB C18 v3.46 for MAC OS X << |