gnupic: TMR0 overflow interrupt on 16F84
Subject:
Re: TMR0 overflow interrupt on 16F84
From:
Ross Mitchell ####@####.####
Date:
28 Jan 2001 13:42:28 -0000
Message-Id: <4.3.2.7.0.20010129004458.00c552e0@mail.matra.com.au>
>
>I'm playing with the TMR0 interrupt on overflow stuff in the 16F84 PIC,
>and it doesn't seem to be working... Am I doing something amazingly
>stupid here? The following code should (I think) toggle the whole of
>PORTA at a frequency of about 15Hz when running on a 4MHz ceramic
>resonator, except it doesn't seem to be working. This should make TMR0
>increment at the speed of the internal clock (1MHz when running at 4MHz),
>and set the prescaler to 1:256. What am I doing wrong here? Thanks.
I am using TMR0 with an 16F877, I have just checked the F84 doc
and they are the
same in this regard.
Just a two things wrong.
A) the TMR0 overflow flag has to be cleared by the software.
If you don't do this then you will get the same interrupt again as
soon as you return.
B) the option register is in bank <drum
roll> ................... ONE !
Your program was:
>include 16f84.inc
>
> GOTO main
>
> ORG 0x0004
>intvec
> COMF PORTA, 1
> RETFIE
>
>main
> BSF STATUS, 5 ; select bank 1
> CLRF TRISA ; PORTA as outputs
> BCF STATUS, 5 ; select bank 0
> CLRF PORTA ; Turn off all of PORTA
> MOVLW b'00000111'
> MOVWF OPTION
> MOVLW b'10100000'
> MOVWF INTCON
>s
> GOTO s
My program would be:
include 16f84.inc
GOTO main
ORG 0x0004
intvec
COMF PORTA, 1
;generally it the full 256 count is not what is wanted, so these lines are
required.
; where T0_tc = (256 - cycles of desired interval)
; movlw T0_tc ;timer reload value for
; movwf TMR0
;the interrupt flag has to be cleared by the software
bcf INTCON,T0IF ;clear the interrupt flag
RETFIE
main
BSF STATUS, 5 ; select bank 1
CLRF TRISA ; PORTA as outputs
MOVLW b'00000111'
MOVWF OPTION ;IN BANK 1
BCF STATUS, 5 ; select bank 0
CLRF PORTA ; Turn off all of PORTA
MOVLW b'10100000'
MOVWF INTCON
s
GOTO s