• AVR Freaks

Hot!Which argument does irq() expect: IRQ_TMR0, TMR0 or 31?

Author
AV380
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2020/06/08 10:15:00
  • Location: 0
  • Status: offline
2020/09/29 09:22:33 (permalink)
0

Which argument does irq() expect: IRQ_TMR0, TMR0 or 31?

PIC18LF47K42
Please explain why using
__interrupt(irq(IRQ_TMR0)) timer0ISR()
results in a compiler error (interrupts.c:12:: error: (2008) unknown "irq" (IRQ_TMR0) in __interrupt attribute/specifier) but
__interrupt(irq(TMR0)) timer0ISR()
and
__interrupt(irq(31)) timer0ISR()
work perfectly.
 
These lines are taken from the pic18lf47k42.h file:
#define                                 IRQ_TMR0            31
extern volatile unsigned char           TMR0                __at(0x3FB6);
 
This is an excerpt from the pic datasheet:
// NOTE 3: Multiple interrupts can be handled by the same ISR if they are
// specified in the "irq(...)" argument. Ex: irq(IRQ_TMR0, IRQ_CCP1)
void __interrupt(irq(IRQ_TMR0), base(0x4008)) TMR0_ISR(void)
{
PIR3bits.TMR0IF = 0; // Clear the interrupt flag
LATCbits.LC0 ^= 1; // ISR code goes here
}
 
#1

7 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 11306
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Which argument does irq() expect: IRQ_TMR0, TMR0 or 31? 2020/09/29 10:36:31 (permalink)
    +3 (3)
    AV380
    PIC18LF47K42
    Please explain why using
    __interrupt(irq(IRQ_TMR0)) timer0ISR()
    results in a compiler error (interrupts.c:12:: error: (2008) unknown "irq" (IRQ_TMR0) in __interrupt attribute/specifier)

    It works here with XC8 v2.20 -- better with void return type.
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 18961
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Which argument does irq() expect: IRQ_TMR0, TMR0 or 31? 2020/09/29 11:33:38 (permalink)
    +2 (2)
    What Compiler Version, and C90 Mode or C99?
    #3
    1and0
    Access is Denied
    • Total Posts : 11306
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Which argument does irq() expect: IRQ_TMR0, TMR0 or 31? 2020/09/29 11:50:48 (permalink)
    +1 (1)
    It works with XC8 v2.20 in both C90 and C99 modes.
    #4
    AV380
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/06/08 10:15:00
    • Location: 0
    • Status: offline
    Re: Which argument does irq() expect: IRQ_TMR0, TMR0 or 31? 2020/09/29 12:10:09 (permalink)
    0
    Hi. I was using XC8 v2.00, C99. I've upgraded to 2.30 and it now works for all three cases.
    Glad that irq(IRQ_TMR0) now works but I'm still confused as to why irq(TMR0) works when the include file it points to via cntl-click contains:
    extern volatile unsigned char           TMR0                __at(0x3FB6);
     
    #5
    1and0
    Access is Denied
    • Total Posts : 11306
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Which argument does irq() expect: IRQ_TMR0, TMR0 or 31? 2020/09/29 12:16:01 (permalink)
    +2 (2)
    AV380
    Glad that irq(IRQ_TMR0) now works but I'm still confused as to why irq(TMR0) works when the include file it points to via cntl-click contains:
    extern volatile unsigned char           TMR0                __at(0x3FB6);

    The XC8 User's Guide shows code that use irq(TMR0). ;)
     
    #6
    dan1138
    Super Member
    • Total Posts : 3910
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Which argument does irq() expect: IRQ_TMR0, TMR0 or 31? 2020/09/29 12:16:34 (permalink)
    +2 (2)
    AV380
    PIC18LF47K42
    Please explain why using
    __interrupt(irq(IRQ_TMR0)) timer0ISR()
    results in a compiler error (interrupts.c:12:: error: (2008) unknown "irq" (IRQ_TMR0) in __interrupt attribute/specifier) but
    __interrupt(irq(TMR0)) timer0ISR()
    and
    __interrupt(irq(31)) timer0ISR()
    work perfectly. ...

    Locate this PDF document within your installation of XC8:

    <YourPathMyVary>/xc8/v2.20/docs/MPLAB_XC8_C_Compiler_User_Guide_for_PIC.pdf

    Read section 5.8 Interrupts for how to use the __interrupt() compiler extension.

    Also the code generated by the MPLABX Code Configurator(MCC) may (or may not) be helpful.
     
    The syntax for irq() and base() are compiler extensions as well so are not findable within any C source code files in the XC8 tool suite. The irq() syntax seems to be the method that correlates the interrupt source principle special function register address with an Interrupt Vector Table(IVT) offset to be populated with a pointer to the Interrupt Service Routine(ISR). The XC8 compiler user guide does not seem to really spell this out.
     
    #7
    AV380
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/06/08 10:15:00
    • Location: 0
    • Status: offline
    Re: Which argument does irq() expect: IRQ_TMR0, TMR0 or 31? 2020/09/29 12:20:04 (permalink)
    +1 (1)
    Thanks all! Very much appreciated.
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5