If you're using the Microchip USB boot-loader, you can drop some of your
defines.
DEFINE LOADER_USED 1 is only required if user code will start at 0. With the
Microchip USB loader, it starts at 800h. You don't need this define.
DEFINE RESET_ORG 800h ' This is required so user code is inserted at 800h (if
using the Microchip USB Bootloader).
DEFINE INTERRUPT_ORG 808h ' This one doesn't really do anything. If you're
using assembler interrupts, then use the PBP DEFINE INTHAND or INTLHAND
options for high/low interrupt vectors.
The Microchip USB loader already has interrupt jump vectors setup in the
loader firmware that will vector to 808h for high pri, and 818h for low pri
interrupts.
Code:
#pragma code high_vector=0x000808
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}
#pragma code
#pragma code low_vector=0x000818
void interrupt_at_low_vector(void)
{
_asm goto low_isr _endasm
}
#pragma code
In the USB loader firmware, at the hardware interrupt vectors, it has GOTO
808h (for high pri) and GOTO 818h (for low pri). You just need to force PBP
to stick your .asm int handlers (or a GOTO each one) in these locations.
To do this, you tell PBP where your high & low interrupt service handlers will
be using the INTHAND & INTLHAND defines below.
DEFINE RESET_ORG 800h ' User code starts at 800h for USB Boot-Loader
DEFINE INTHAND my_high_isr ' High priority int handler
DEFINE INTLHAND my_low_isr ' Low priority int handler
Now add your assembler interrupt handlers like this;
Code:
ASM
my_high_isr
; do stuff here
RETFIE FAST
ENDASM
ASM
my_low_isr
; do stuff here
RETFIE
ENDASM
PBP will place a GOTO my_high_isr at location 808h, and a GOTO my_low_isr
at 818h.
The rest of your code will start just after location 818h.
You have re-mapped the reset vector to 800h with DEFINE RESET_ORG 800h
so PBP knows where to stick these. It simply adds 08h or 18h to the reset
address for the high/low priority interrupt locations.
The USB firmware vectors to 808h for high pri, and 818h for low pri, and PBP
has placed GOTO's in these locations vectoring to your re-mapped .asm
interrupt handlers.
If you're 100% sure you have all interrupts disabled, and you're never planning
to use them, then you can drop the interrupt defines altogether.
If you're not sure, or you do plan to use interrupts, and you're using the USB
loader from Microchip, then it's a really good idea to setup these vectors.
If you don't, then PBP will place 'user' code in locations the loader will vector
to when an interrupt happens. Then you have no idea what's going to happen.
Bookmarks