wcgan
Member level 2
pic timer interrupt
Hi all,
I have tried the code below to generate an interrupt after timer1 overflow. but it does not working.
Can anyone help to correct my code? or give me a simple example of timer interrrupt?
thanks.
Hi all,
I have tried the code below to generate an interrupt after timer1 overflow. but it does not working.
Can anyone help to correct my code? or give me a simple example of timer interrrupt?
thanks.
Code:
#include <timers.h>
#include <p18cxxx.h>
void timer1_isr(void);
void main()
{
TRISD = 0x00; // RD4-7 for LCD, RD3 for SR_DATdA, RD2 for output to CPLD, RD0 for nRESET output
LATD = 0xFF;
PORTD = 0xFF; // RESET alwasy high at power up
PORTEbits.RDPU =0;
OpenTimer1(TIMER_INT_ON & T1_8BIT_RW & T1_SOURCE_INT & T1_PS_1_8 & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF);
WriteTimer1(0x00FF);
RCONbits.IPEN=1;
RCONbits.SBOREN=0;
INTCON=0b10000000;
IPR1bits.TMR1IP=1;
PIE1bits.TMR1IE=1;
while(1)
{
}
}
void high_ISR (void)
{
_asm goto timer1_isr _endasm
}
#pragma interrupt timer1_isr
void timer1_isr(void)
{
PIR1bits.TMR1IF=0;
WriteTimer1(0x00FF);
PORTDbits.RD7=~PORTDbits.RD7;
}