Philip Pemberton wrote:
{Quote hidden}> OK, this is just getting weird...
>
> I had external interrupts working in the JAL prototype of my
> remote-control receiver code, but I'm rewriting it in C18 (mainly
> because I can do floating-point calculations for timer preload and
> threshold values; JAL AIUI only handles integer math).
>
> The thing is, I'm not seeing any interrupts -- none at all. I put a
> breakpoint on the "goto ISR" line, and the PIC didn't break. I also
> didn't see anything on the logic analyser....
>
> I must be doing something stupid, but I can't for the life of me figure
> out what:
>
> #include <p18cxxx.h>
> #pragma config OSC = HS // High Speed Crystal oscillator
> #pragma config WDT = OFF // Watchdog timer off
> #pragma config LVP = OFF // Low-voltage programming off
> #pragma config MCLRE = ON // MCLR (reset) on
> #pragma config FSCM = 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 = 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 = TMR0L;
> TMR0L = 0;
> overflow = INTCONbits.TMR0IF;
> INTCONbits.TMR0IF = 0;
>
> // detect RB0 int flag
> if (INTCONbits.INT0IF) {
> char pol;
>
> // clear interrupt flag
> INTCONbits.INT0IF = 0;
>
> // store bit polarity, then flip to other polarity
> pol = INTCON2bits.INTEDG0;
> INTCON2bits.INTEDG0 = !INTCON2bits.INTEDG0;
> }
> }
>
> void main(void)
> {
> // Initialise pin directions
> LATA = LATB = 0; // Clear port holding registers
> TRISA = TRISB = 0; // Default to all outputs
> PIN_IR_DIR = 1; // IR pin is an input
>
> // Set up timer 0
> T0CON = 0; // Clear timer control register
> #ifdef TIMER0_USE_PRESCALER
> T0CONbits.PSA = 1; // Assign prescaler to timer0
> T0CONbits.T0PS0 = (TIMER0_PRESCALER_SETTING & 1)==1;
> T0CONbits.T0PS1 = (TIMER0_PRESCALER_SETTING & 2)==2;
> T0CONbits.T0PS2 = (TIMER0_PRESCALER_SETTING & 4)==4;
> #else
> T0CONbits.PSA = 0; // Disable prescaler
> #endif
> TMR0L = 0; // Clear timer0 value
>
> // Set up interrupts
> INTCON2bits.INTEDG0 = IPOL_ACT; // Trigger RB0 interrupt on
> // active-going edge
> INTCONbits.INT0IF = 0; // Clear RB0 interrupt flag
> INTCONbits.INT0IE = 1; // Enable INT0 interrupt
> // The ISR handles the timer-0 overflow interrupt.
> INTCONbits.GIE = 1; // Enable interrupts (globally)
>
> debug_word(0xCAFE);
> debug_word(0xBABE);
>
> for (;;) {
> }
> }
>
>
> Can anyone see what I'm doing wrong here?
> The chip seems to be acting as
> if GIE were never set, but the SFR window suggests it *is* being set (as
> is INT0IE)...
> What intterrupts are you expecting? Your code seems to talk about a 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 an analog input.
> Thanks,
>