Hello all. I cannot persuade TMR1 interrupt to toggle an LED. I tried the "ON INTERRUPT...." method and that works fine, toggling the LED 3 or 4 times a second. But I cannot work out how to do this manually by polling the TMR1IF (PIR1.0) flag. I wonder if anyone has any ideas? I have spend hours reading through threads (including the Olympic Timer example thread) but to no avail. Presumably the solution is simple, but I can't work out what it is.
Many thanks in advance.
Jonathan.
Code:define OSC 20 TRISB = %11101111 ' PORTB.4 output led var PORTB.4 led = 0 INTCON = 0 PIR1 = $00 ' clear interupt flags TMR1H = 0 TMR1L = 0 T1CON = %00110001 ' TMR1 on, prescaler=1:8, clock=(Fosc/4) INTCON = $C0 ' Enable global and peripheral interupts PIE1 = $01 ' Enable TMR1 overflow interrupt main: if PIR1.0 then led = not led TMR1H = 0 ' reset timer1 TMR1L = 0 PIR1 = $00 ' clear interrupt flags endif goto main end




Bookmarks