;;;;;;; Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cblock Bank0RAM
T0Count
Y1
endc
;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org H'000' ;Reset vector
goto Mainline ;Branch past tables
org H'004' ;Unused interrupt vector
Stop
goto Stop ;Stop if an interrupt accidently occurs
;;;;;;; Tables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; No tables needed
;;;;;;; End of Tables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; Mainline program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Mainline
call Initial ;Initialize everything
;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine performs all initializations of variables and registers.
Initial
bsf STATUS,RP0 ;Set register access to bank 1
clrf TRISC ;Set up all bits of PORTC as outputs
bcf STATUS,RP0 ;Set register access back to bank 0
movlw 000
movwf T0Count
movlw 100
bcf STATUS,RP0 ;change to bank 0
movwf TMR0
bsf STATUS,RP0 ;change to bank 1
bsf OPTION_REG,0
bcf OPTION_REG,1
bsf OPTION_REG,2 ;set to 5
bcf OPTION_REG,3
bcf OPTION_REG,5
bcf STATUS,RP0 ;change to bank 0
loop1 btfss PORTB,0 ;Check if button is pressed
clrf T0Count
movf T0Count,w
movwf PORTC
btfss PORTB,0
goto loop2
goto loop1
;Check the T0IE, if it is set, then increment T0Count
loop2 btfsc INTCON,T0IF
incf T0Count
call keeplight
movf T0Count,w
movwf PORTC
btfsc INTCON,T0IF
bcf INTCON,T0IF
btfsc PORTB,0
goto loop1
goto loop2
return
;;;;;;; keeplight subroutine;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;test each bit of T0 to check if it equals 1, if any bit
;is not 1, then T0 is not 255, then exit this subroutine
keeplight
btfss T0Count,0
return
btfss T0Count,1
return
btfss T0Count,2
return
btfss T0Count,3
return
btfss T0Count,4
return
btfss T0Count,5
return
btfss T0Count,6
return
btfss T0Count,7
return
call lightson
return
lightson
movlw B'11111111'
clrf T0Count
movwf PORTC
btfss PORTB,0
call lightson
goto loop1
return
end