The Microchip USB loaders are configured to run on Microchip USB dev boards and they use SW2 to determine if it jumps to the loader or user code at POR. In the USB loader version I have, io_cfg.h has SW2 defined as the switch used to toggle between loader & user mode.
#define sw2 PORTAbits.RA3 // this means RA3 is the switch input pin
In main.c they sample this switch at power up to determine the mode;
Code:
//Check Bootload Mode Entry Condition
if(sw2 == 1) // use sw2 to determine if the device should enter the bootloader, or main app code
{
ADCON1 = 0x07; // Restore "reset value" of the ADCON1 register
_asm
goto 0x1000 // If not bootloader, go straight to the main application remapped "reset" vector.
_endasm
}
So if RA3 = 1 at power up it jumps to your code. If RA3 = 0 it enters boot-loader mode. If RA3 is floating on your board that would explain why it's a hit & miss at POR since the input may be read as either high or low when floating.
Note the goto 0x1000. This is where your code should start. Older versions started at 0x800.
Bookmarks