For reference, here is the solution. The LED is toggled once every second by monitoring the TMR1 interrupt flag. 16F88.
Jonathan.
Code:
define OSC 20
' SET UP PORTS
TRISB = 101111 ' PORTB.4 output
' SET UP TMR1
T1CON = 0 ' prescaler=1:1, clock=(Fosc/4)
PIE1.0 = 1 ' Enable TMR1 overflow interrupt
INTCON.6 = 0 ' Disable peripheral interrupts
INTCON.7 = 0 ' Disable global interrupts (disable GIE and PEIE because there
' is no ISR, polling PIR1.0 (TMR1IF) manually instead)
' DECLARE VARIABLES
led var PORTB.4
overflow_counter var word
tmr1_preload var word
' INIT PROGRAMME
init:
led = 0
overflow_counter = 0
tmr1_preload = 15536 ' 15536 for overflow every 10 ms
TMR1H = tmr1_preload.highbyte
TMR1L = tmr1_preload.lowbyte
T1CON.0 = 1 ' Start TMR1
main:
if PIR1.0 = 1 then ' if TMR1IF is set
overflow_counter = overflow_counter + 1
if overflow_counter = 100 then ' 100 overflows = 1 second
led = not led ' toggle led
overflow_counter = 0 ' reset overflow counter
endif
TMR1H = tmr1_preload.highbyte ' reset TMR1 with preload value
TMR1L = tmr1_preload.lowbyte
PIR1.0 = 0 ' clear TMR1IF
endif
goto main
end
Bookmarks