Can anyone see what the heck I am doing wrong? This code for Timer1 interrupt used to work now it no longer interrupts :
The chip is a Pic 18F27J53 running 8MHZ internal OSC.
Here is the interrupt routine:
I set a breakpoint in on i=1 and it never breaks there. Plus LATB3 is not being toggled though I can toggle in in a loop in my main code.
The chip is a Pic 18F27J53 running 8MHZ internal OSC.
Rich (BB code):
void main()
{
TRISBbits.TRISB3 = 0;
LATBbits.LATB3 = 0;
// 8MHZ for 18F27J53
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
// Set up global interrupts
RCONbits.IPEN = 1; // Enable priority levels on interrupts
INTCONbits.GIEL = 1; // Low priority interrupts allowed
IPR1bits.TMR1IP = 0; // Timer1 is low priority interrupt
PIE1bits.TMR1IE = 1; // Enable interrupts for Timer 1
//Timer1 Registers Prescaler= 1 - TMR1 Preset = 65475 - Freq = 32786.89 Hz - Period = 0.000030 seconds
T1CONbits.T1CKPS1 = 0; // bits 5-4 Prescaler Rate Select bits
T1CONbits.T1CKPS0 = 0; // bit 4
T1CONbits.T1OSCEN = 1; // bit 3 Timer1 Oscillator Enable Control bit 1 = on
T1CONbits.NOT_T1SYNC = 1; // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
T1CONbits.TMR1CS = 0; // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
TMR1H = 255; // preset for timer1 MSB register
TMR1L = 195; // preset for timer1 LSB register
T1CONbits.TMR1ON = 1; // bit 0 enables timer
while(1);
}
Rich (BB code):
void InterruptServiceLow(void);
// Low priority interrupt vector
#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow (void)
{
_asm
goto InterruptServiceLow //jump to interrupt routine
_endasm
}
/** D E C L A R A T I O N S *******************************************/
#pragma code // declare executable instructions
#pragma interruptlow InterruptServiceLow
void InterruptServiceLow(void)
{
int i;
i=1;
// Check for Timer1 Overflow Interrupt
if (PIR1bits.TMR1IF)
{
i = 1;
LATBbits.LATB3 =~ LATBbits.LATB3;
TMR1H = 255; // preset for timer1 MSB register
TMR1L = 195; // preset for timer1 LSB register
PIR1bits.TMR1IF = 0; // clear flag
}
}
Last edited: