pic16f18855, help with assembly

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Hi guys

So I was looking at some bootloader source code, with the intention to understand how it works. I think I got the basic idea, but there are a few details that I don't understand and I need some help with these.

The first part that I am not quire understand is how it remap the interrupt to a new locations, here is the source code, where can I find more info about this? I can tell what they do from the comments, but I don't understand them at all.

Code:
// *****************************************************************************
// The bootloader code does not use any interrupts.
// However, the application code may use interrupts.
// The interrupt vector on a PIC16F is located at
// address 0x0004.
// The following function will be located
// at the interrupt vector and will contain a jump to
// the new application interrupt vector

    asm ("psect  intentry,global,class=CODE,delta=2");
    asm ("pagesel " str(NEW_INTERRUPT_VECTOR));
    asm ("GOTO " str(NEW_INTERRUPT_VECTOR));
Thanks guys!

PS: using XC8 compiler.
 

jpanhalt

Joined Jan 18, 2008
11,087
Interesting read. I knew about that option but had been too lazy to look it up, as it does not apply to what I do.

It has a 2010 copyright. I wonder whether MPLabX procedures are the same? Hopefully, this comment is not too OT, but the suggested directive, "Extended Instruction Set Enable bit = Disable" seems counterproductive. I couldn't find it mentioned elsewhere in the document and wonder whether that setting only applies to the bootloader operation* and not the the main firmware?

John

*Might make some sense for firmware that is to be installed regardless of whether the chip is an enhanced version.
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
hi bug,
Look thru this boot loader tutorial PDF.

E
Thanks for the link.

I think that's how they remap the interrupt in their tutorial.
Code:
// Since the bootloader isn't going to write the normal reset vector at 0, we have
// to generate our own remapped reset vector at the address specified in the
// bootloader firmware.
#pragma code AppVector = 0x400          // must match bootloader source code definition
void AppVector(void)
{
    _asm GOTO _startup _endasm
}

// For PIC18 devices the high priority interrupt vector is normally positioned at
// address 0008h, but the bootloader resides there. Therefore, the
// bootloader's interrupt vector code is set up to branch to our code at 0408h.
#pragma code AppHighIntVector = 0x408   // must match bootloader source code definition
void AppHighIntVector(void)
{
    _asm GOTO high_isr _endasm          // branch to the high_isr() function to handle priority interrupts.
}

#pragma code AppLowIntVector = 0x418    // must match bootloader source code definition
void low_vector(void)
{
  _asm GOTO low_isr _endasm             // branch to the low_isr() function to handle priority interrupts.
}

#pragma code                            // return to the default code section
If I want to do it in XC8, I guess I can follow the instruction here:
http://microchipdeveloper.com/faq:38
And do something like this?? Am I correct?
Code:
// put code in the address 0x008 (in the bootloader)
// and jump to 0x408, high interrupt vector in the application code 
void AppHighIntVector(void) @ 0x008
{
    // asm code: goto 0x408
}

// put code in the address 0x018 (in the bootloader)
// and jump to 0x418, low interrupt vector in the application code 
void low_vector(void) @ 0x018
{
   // asm code: goto 0x418    
}
PS: edited
 
Last edited:

Thread Starter

bug13

Joined Feb 13, 2012
2,002
So I did some test, my follow code seem to do the same things, any comments?

Code:
#define USE_METHOD_1

#ifdef USE_METHOD_1

// stop xc8 compiler to remove un-used function
asm("GLOBAL _isr_jump");
// put code in interrupt vector
void isr_jump(void) @ 0x08 {
    // jump to interrupt code
    asm("goto _isr_test");
}

#else

// put code in interrupt vector
asm("PSECT intcode");
// jump to interrupt code
asm("goto _isr_test");

#endif
 
Top