Yeah, that fixed the issue. That was a typo. Best Regards, Manu On Wed, May 9, 2012 at 8:51 PM, Bob Ammerman wrote: > > Just a guess... > > If you misspell the name of the interrupt handler on the #pragma interrup= t > statement the compiler wouldn't know to end the routine with a RETFIE > instead of a RETURN. > > -- Bob Ammerman > RAm Systems > > ----- Original Message ----- > From: "Joe Wronski" > To: "Microcontroller discussion list - Public." > Sent: Wednesday, May 09, 2012 10:54 AM > Subject: Re: [PIC]Interrupts with 18F4550 and C18 > > > > Without actually digging into the doc for the 18F part in the example > > (18C452 ?), I can give some answers: > > o Unconditional goto is due to limited program space in the interrupt > > vector area. > > o Retfie is generated by the compiler, probably due to the #pragma > > interrupt directive. =A0Look at View->Disassembly Listing after buildin= g. > > o Can't speak to the GIE issue without further digging, but if it is > > disabled by the interrupt mechanism, your cods should re-enable it, > > unless it is implicitly done by the retfie. > > > > There should be no differences in the chip operation whether using C or > > assembler. =A0Always look to the assembler produced by the compiler. > > > > Here is the interrupt exit code produced by C18 including the "missing" > > retfie: > > > > =A0 00F2 =A0 =A052E5 =A0 =A0 MOVF 0xfe5, F, ACCESS > > =A0 00F4 =A0 =A0CFE5 =A0 =A0 MOVFF 0xfe5, 0xfda > > =A0 00F6 =A0 =A0FFDA =A0 =A0 NOP > > =A0 00F8 =A0 =A00011 =A0 =A0 RETFIE 0x1 > > > > Joe W > > > > > > > > On 5/9/2012 3:30 AM, Manu Abraham wrote: > >> Hi, > >> > >> The C18 example states that an interrupt handler is to be defined thus= : > >> (in MCC18\examples\Interrupt\main.c) > >> > >> //--------------------------------------------------------------------= -------- > >> // High priority interrupt vector > >> > >> #pragma code InterruptVectorHigh =3D 0x08 > >> void > >> InterruptVectorHigh (void) > >> { > >> =A0 =A0_asm > >> =A0 =A0 =A0goto InterruptHandlerHigh //jump to interrupt routine > >> =A0 =A0_endasm > >> } > >> > >> > >> //--------------------------------------------------------------------= -------- > >> // High priority interrupt routine > >> > >> #pragma code > >> #pragma interrupt InterruptHandlerHigh > >> > >> void > >> InterruptHandlerHigh () > >> { > >> =A0 =A0if (INTCONbits.TMR0IF) > >> =A0 =A0 =A0{ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 //check for TMR0 overflow > >> =A0 =A0 =A0 =A0INTCONbits.TMR0IF =3D 0; =A0 =A0 =A0 =A0 =A0 =A0//clear= interrupt flag > >> =A0 =A0 =A0 =A0Flags.Bit.Timeout =3D 1; =A0 =A0 =A0 =A0 =A0 =A0//indic= ate timeout > >> =A0 =A0 =A0 =A0LATBbits.LATB0 =3D !LATBbits.LATB0; //toggle LED on RB0 > >> =A0 =A0 =A0} > >> } > >> > >> > >> But I can't seem to figure out why that INTCONbits.GIEH is disabled > >> after once it has run through the handler. In asm, the Global Interrup= t > >> handler is enabled after a retfie, but with C18 and the 18F4550, this > >> doesn't seem to be the case, I do need a retfie as follows, for the > >> interrupt to be re enabled. Any idea why it is thus ? > >> > >> Additionally, I have this question, the ISR is unconditionally jumping > >> to > >> another function. Especially in an ISR, I can't really reason why that > >> would be a good practice ? =A0(Although I can assume that the function= s > >> would expand to labels in asm. But still doesn't explain the missing > >> retfie) > >> > >> > >> > >> void low_isr(void) > >> { > >> =A0 =A0 =A0if ((PIE1bits.TMR2IE =3D=3D 1)&& =A0(PIR1bits.TMR2IF =3D=3D= 1)) { > >> =A0 =A0 =A0 =A0 =A0PIR1bits.TMR2IF =3D 0; > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 DisplayDigit(segment, display[segment]= ); > >> =A0 =A0 =A0} > >> =A0 =A0 =A0_asm > >> =A0 =A0 =A0 =A0 =A0retfie 0 > >> =A0 =A0 =A0_endasm > >> } > >> > >> #pragma code low_vector =3D 0x18 > >> void low_vector (void) > >> { > >> =A0 =A0 =A0_asm goto low_isr _endasm > >> } > >> > >> void init_timer2(void) > >> { > >> =A0 =A0 =A0OpenTimer2(TIMER_INT_ON& =A0T2_PS_1_4& =A0T2_POST_1_1); > >> =A0 =A0 =A0 PR2 =3D 223; > >> =A0 =A0 =A0RCONbits.IPEN =A0 =A0=3D 1; /* Interrupt priority enable */ > >> =A0 =A0 =A0 =A0 =A0IPR1bits.TMR2IP =A0 =A0=3D 0; /* TMR2 Low priority = */ > >> =A0 =A0 =A0 INTCONbits.GIEL =3D 1; > >> =A0 =A0 =A0 =A0 INTCONbits.GIEH =3D 1; > >> } > >> > >> void main() > >> { > >> =A0 =A0 =A0TRISD =3D 0; > >> =A0 =A0 =A0TRISC =3D 0; > >> =A0 =A0 =A0init_timer2(); > >> > >> =A0 =A0 =A0while (1) { > >> > >> =A0 =A0 =A0 =A0 =A0} > >> } > >> > >> Thanks, > >> Manu > > > > -- > > http://www.piclist.com PIC/SX FAQ & list archive > > View/change your membership options at > > http://mailman.mit.edu/mailman/listinfo/piclist > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .