I am new to interrupts/timers and I cant seem to get timer0 to work at all. I am simply blinking one led and when the timer overflows it should turn on another led but it isn't. just the first led is blinking.
Code:
list p=16f767
#include <P16F767.inc>
d1 equ 20h
d2 equ 21h
d3 equ 22h
TEMP equ 23h
;**********************************************************************
org 0x0000
goto START
org 0x0004
movwf TEMP ; save w register
bsf PORTA,1 ; turn on led 2
movfw TEMP
bcf INTCON,T0IF
retfie
START
bcf STATUS, RP1
bcf STATUS, RP0 ;bank 0
clrf PORTA
bsf STATUS, RP0 ;bank 1
movlw 62h ; 4mhz clk
movwf OSCCON
movlw 00h
movwf OSCTUNE
movlw 0Fh ; Configure all pins
movwf ADCON1 ; as digital
movlw 00h ; all output
movwf TRISA
bcf STATUS, RP0 ; Bank0
movlw b'00000000'
movwf OPTION_REG
bsf INTCON,GIE ; enable interrupts
bsf INTCON,TMR0IE ; enable timer0
bcf INTCON,TMR0IF ; clear timer overflow
LOOP
bsf PORTA,0 ; turn on led
movlw 0FFh
call DELAY ; delay 255 milli
bcf PORTA,0 ; turn off led
movlw 0FFh
call DELAY ; delay 255 milli
goto LOOP
;---------------------------------
; DELAY ROUTINE delays n milliseconds
;---------------------------------
DELAY
movwf d3
DELAY_1
;993 cycles
movlw 0xC6
movwf d1
movlw 0x01
movwf d2
DELAY_0
decfsz d1, f
goto $+2
decfsz d2, f
goto DELAY_0
decfsz d3, f
goto DELAY_1
return
END
Last edited: