Philip Pemberton wrote: > OK, this is just getting weird... > > I had external interrupts working in the JAL prototype of my=20 > remote-control receiver code, but I'm rewriting it in C18 (mainly=20 > because I can do floating-point calculations for timer preload and=20 > threshold values; JAL AIUI only handles integer math). > > The thing is, I'm not seeing any interrupts -- none at all. I put a=20 > breakpoint on the "goto ISR" line, and the PIC didn't break. I also=20 > didn't see anything on the logic analyser.... > > I must be doing something stupid, but I can't for the life of me figure=20 > out what: > > #include > #pragma config OSC =3D HS // High Speed Crystal oscillator > #pragma config WDT =3D OFF // Watchdog timer off > #pragma config LVP =3D OFF // Low-voltage programming off > #pragma config MCLRE =3D ON // MCLR (reset) on > #pragma config FSCM =3D OFF // Failsafe clock monitor off > > // timer0 prescaler settings > #define TIMER0_USE_PRESCALER > #define TIMER0_PRESCALER_SETTING 5 > > // Infra-red receiver > #define PIN_IR PORTBbits.RB0 > #define PIN_IR_DIR TRISBbits.TRISB0 > > void isr(void); > > // ISR stub code > #pragma code HIGH_INTERRUPT_VECTOR =3D 0x8 > void high_ISR (void) > { > _asm > goto isr > _endasm > } > #pragma code > > // Interrupt Service Routine > #pragma interrupt isr > void isr(void) > { > unsigned char tval; > char overflow; > > // Store timer value and overflow flag and rearm the timer > tval =3D TMR0L; > TMR0L =3D 0; > overflow =3D INTCONbits.TMR0IF; > INTCONbits.TMR0IF =3D 0; > > // detect RB0 int flag > if (INTCONbits.INT0IF) { > char pol; > > // clear interrupt flag > INTCONbits.INT0IF =3D 0; > > // store bit polarity, then flip to other polarity > pol =3D INTCON2bits.INTEDG0; > INTCON2bits.INTEDG0 =3D !INTCON2bits.INTEDG0; > } > } > > void main(void) > { > // Initialise pin directions > LATA =3D LATB =3D 0; // Clear port holding registers > TRISA =3D TRISB =3D 0; // Default to all outputs > PIN_IR_DIR =3D 1; // IR pin is an input > > // Set up timer 0 > T0CON =3D 0; // Clear timer control register > #ifdef TIMER0_USE_PRESCALER > T0CONbits.PSA =3D 1; // Assign prescaler to timer0 > T0CONbits.T0PS0 =3D (TIMER0_PRESCALER_SETTING & 1)=3D=3D1; > T0CONbits.T0PS1 =3D (TIMER0_PRESCALER_SETTING & 2)=3D=3D2; > T0CONbits.T0PS2 =3D (TIMER0_PRESCALER_SETTING & 4)=3D=3D4; > #else > T0CONbits.PSA =3D 0; // Disable prescaler > #endif > TMR0L =3D 0; // Clear timer0 value > > // Set up interrupts > INTCON2bits.INTEDG0 =3D IPOL_ACT; // Trigger RB0 interrupt on > // active-going edge > INTCONbits.INT0IF =3D 0; // Clear RB0 interrupt flag > INTCONbits.INT0IE =3D 1; // Enable INT0 interrupt > // The ISR handles the timer-0 overflow interrupt. > INTCONbits.GIE =3D 1; // Enable interrupts (globally) > > debug_word(0xCAFE); > debug_word(0xBABE); > > for (;;) { > } > } > > > Can anyone see what I'm doing wrong here?=20 > The chip seems to be acting as=20 > if GIE were never set, but the SFR window suggests it *is* being set (as= =20 > is INT0IE)... > =20 What intterrupts are you expecting? Your code seems to talk about a=20 timer interrupt but doesn't seem to actually enable the timer interrupt. As for the int0 intterrupt it looks to me like you may have RB0 set as=20 an analog input. > Thanks, > =20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .