Monchichack
New Member
Hi,
I am not new to programming micro controllers but I have never got above the hobby level so everytime I revisit them I have to re-learn.
I am currently having problems receiving an interrupt from TMR0. I have set up a small test program to test the interrupt and also the TMR0 interrupt flag (INTCON,TOIF) but neither seem to be triggering? It is embarrasing to say I have actually been staring at this for 2 days now which is probably my downfall in resolving this issue.
Here is the code,
I am sure I am making a stupid mistake and I would be grateful to anyone who points it out.
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
w_temp EQU b'1010'
timer1 EQU b'1011'
timer2 EQU b'1100'
status_temp EQU b'1101'
org 00 ; processor reset vector
goto Start
org 04
goto ISR
Init clrf PORTA
clrf PORTB
clrf TMR0
bsf STATUS,RP0
movlw b'00000000'
tris PORTB
movlw b'00000'
tris PORTA
movlw b'11000111'
option
bcf INTCON,T0IF
movlw b'10100000'
movwf INTCON
retlw 0
Delay
movlw D'44'
movwf timer2
del_loop1 movlw D'44'
movwf timer1
del_loop2 decfsz timer1,F
goto del_loop2
decfsz timer2,F
goto del_loop1
retlw 0
ISR
bcf STATUS,RP0
movwf w_temp
movfw STATUS
movwf status_temp
movlw b'00000000' ;if interrupt occurs PORTB is
movwf PORTB ;cleared
call Delay
movfw status_temp
STATUS register
movwf STATUS
swapf w_temp,f
swapf w_temp,w
bcf INTCON,T0IF
retfie
Start call Init
Main call Delay
bcf STATUS,RP0
movlw b'00000'
movwf PORTA
movlw b'11111111' ;Sets PORTB on
movwf PORTB
call Delay
btfss INTCON,T0IF
goto Main
bcf INTCON,T0IF
movlw b'00000000' ;If TOIF bit is triggered PORTB is
movwf PORTB ;cleared
call Delay
goto Main
End
Also,, while I have your attention:
The final program I am trying to write is going to switch an output port on for 10ms - 9.99 seconds and switch it off for 10ms to 9.99s. Both periods need to be independently adjusted and displayed on 3 7-segment displays when doing so. I have the displys working but I am currently holding the code in 3 registers for hundreds, tens and units and my timer inc/dec will be in another 2 files which I am not sure how to link?
Am I overlooking an easier way to do this program?
Any advise would be appreciated.
Thanks in advance
Chris
I am not new to programming micro controllers but I have never got above the hobby level so everytime I revisit them I have to re-learn.
I am currently having problems receiving an interrupt from TMR0. I have set up a small test program to test the interrupt and also the TMR0 interrupt flag (INTCON,TOIF) but neither seem to be triggering? It is embarrasing to say I have actually been staring at this for 2 days now which is probably my downfall in resolving this issue.
Here is the code,
I am sure I am making a stupid mistake and I would be grateful to anyone who points it out.
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
w_temp EQU b'1010'
timer1 EQU b'1011'
timer2 EQU b'1100'
status_temp EQU b'1101'
org 00 ; processor reset vector
goto Start
org 04
goto ISR
Init clrf PORTA
clrf PORTB
clrf TMR0
bsf STATUS,RP0
movlw b'00000000'
tris PORTB
movlw b'00000'
tris PORTA
movlw b'11000111'
option
bcf INTCON,T0IF
movlw b'10100000'
movwf INTCON
retlw 0
Delay
movlw D'44'
movwf timer2
del_loop1 movlw D'44'
movwf timer1
del_loop2 decfsz timer1,F
goto del_loop2
decfsz timer2,F
goto del_loop1
retlw 0
ISR
bcf STATUS,RP0
movwf w_temp
movfw STATUS
movwf status_temp
movlw b'00000000' ;if interrupt occurs PORTB is
movwf PORTB ;cleared
call Delay
movfw status_temp
STATUS register
movwf STATUS
swapf w_temp,f
swapf w_temp,w
bcf INTCON,T0IF
retfie
Start call Init
Main call Delay
bcf STATUS,RP0
movlw b'00000'
movwf PORTA
movlw b'11111111' ;Sets PORTB on
movwf PORTB
call Delay
btfss INTCON,T0IF
goto Main
bcf INTCON,T0IF
movlw b'00000000' ;If TOIF bit is triggered PORTB is
movwf PORTB ;cleared
call Delay
goto Main
End
Also,, while I have your attention:
The final program I am trying to write is going to switch an output port on for 10ms - 9.99 seconds and switch it off for 10ms to 9.99s. Both periods need to be independently adjusted and displayed on 3 7-segment displays when doing so. I have the displys working but I am currently holding the code in 3 registers for hundreds, tens and units and my timer inc/dec will be in another 2 files which I am not sure how to link?
Am I overlooking an easier way to do this program?
Any advise would be appreciated.
Thanks in advance
Chris