Been trying to get a timer to fire off on my 16F870 for a while now...
I tried TMR0 since I had experience setting it on from my 16F84a. Here
are the steps I take:
Set up TMR0 configuration stuff, prescalar, etc. (watchdog disabled of
course)
Enable T0 interrupt
Enable Global Interrupts
wait for the magic to happen. nothing. is there something I'm missing
on the 16F870 to get a timer to go off? My code worked fine on my 16F84
so I just changed it to fit a 870...
So I nuked that code, and tried to use TMR1 since it was 16 bit and
would be a bit slower to work with. Here's my setup (I saved the code
this time! :)
ISR
movwf W_TEMP ; Copy W to TEMP
register
swapf STATUS,w ; Swap status to be
saved into W
clrf STATUS ; bank 0, regardless of
current bank, Clears IRP,RP1,RP0
movwf STATUS_TEMP ; Save status to bank
zero STATUS_TEMP register
movf PCLATH,w ; Only required if using
pages 1, 2 and/or 3
movwf PCLATH_TEMP ; Save PCLATH into W
clrf PCLATH ; Page zero, regardless
of current page
incf EIGHTTEEN,f ; counter++
movlw 18
subwf EIGHTTEEN,w
btfss STATUS,C ; if EIGHTTEEN < 18
goto ISR_DONE ; do nothing
incf MINUTES ; otherwise do this
ISR_DONE
movf PCLATH_TEMP,w ; Restore PCLATH
movwf PCLATH ; Move W into PCLATH
swapf STATUS_TEMP,w ; Swap STATUS_TEMP
register into W
movwf STATUS ; Move W into STATUS
register
swapf W_TEMP,f ; Swap W_TEMP
swapf W_TEMP,w ; Swap W_TEMP into W
bcf PIR1,TMR1IF ; handle TMR1 flag
retfie
*snip*
and nothing happens, MINUTES never gets incremented, nor does TMR1H/L as
I've outputted them as well...
Any thoughts? This is confusing me as this should be totally simple!
Nick Veys wrote:
>
> Been trying to get a timer to fire off on my 16F870 for a while now...
>
> I tried TMR0 since I had experience setting it on from my 16F84a. Here
> are the steps I take:
>
> Set up TMR0 configuration stuff, prescalar, etc. (watchdog disabled of
> course)
> Enable T0 interrupt
> Enable Global Interrupts
This should work...
org 0h ; startup vector = 0000
goto Start
org 4h
; save registers etc.
bcf INTCON,T0IF
; do something
; restore registers
retfie
;
; ----------
; CODE START
; ----------
;
Start ; port setups etc.
Nick Veys wrote:
>Been trying to get a timer to fire off on my 16F870 for a while now...
>
>I tried TMR0 since I had experience setting it on from my 16F84a. Here
>are the steps I take:
>
>Set up TMR0 configuration stuff, prescalar, etc. (watchdog disabled of
>course)
>Enable T0 interrupt
>Enable Global Interrupts
>
>wait for the magic to happen. nothing. is there something I'm missing
>on the 16F870 to get a timer to go off? My code worked fine on my 16F84
>so I just changed it to fit a 870...
.........>
Nick, I did not parse your code, but here is a suggestion for
the next time you're beating your head against the wall over
something like this. Simplify it to 1 step at a time. Do the
timer stuff, and get it working correctly via polling the IF
flag without doing the interrupts. Once that is good, then add
in the interrupt stuff.
ISR
MOVWF W_TEMP ;Copy W to TEMP register
SWAPF STATUS,W ;Swap status to be saved into W
CLRF STATUS ;bank 0, regardless of current bank, Clears IRP,RP1,RP0
MOVWF STATUS_TEMP ;Save status to bank zero STATUS_TEMP register
MOVF PCLATH, W ;Only required if using pages 1, 2 and/or 3
MOVWF PCLATH_TEMP ;Save PCLATH into W
CLRF PCLATH ;Page zero, regardless of current page
bcf INTCON,T0IF
MOVF PCLATH_TEMP, W ;Restore PCLATH
MOVWF PCLATH ;Move W into PCLATH
SWAPF STATUS_TEMP,W ;Swap STATUS_TEMP register into W
;(sets bank to original state)
MOVWF STATUS ;Move W into STATUS register
SWAPF W_TEMP,F ;Swap W_TEMP
SWAPF W_TEMP,W ;Swap W_TEMP into W
retfie
Cut and dry, once everything is set up, I output the TMR0 value (comes
out in HEX) to my LCD, along w/a test character to make sure it's alive.
The HEX changes with every startup, but never changes during my looping,
I always get some random HEX value, and an 'A' printed...
I've also tried adding a variable, having the ISR increment that
variable, and outputting THAT instead on TMR0, in which case that
variable always outputs 0x00 since I initialize it in the beginning...