;******************************************************************
;* *
;* *
;* OEM timer (GP0 = Relay output, GP1 = Activity LED) *
;* *
;* MPLAB: 8.50 (tabs=8) *
;* MPASM: 5.35 *
;* *
;******************************************************************
errorlevel -302 ; suppress bank warnings
radix dec
include "p10f200.inc"
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF
;--< variables >---------------------------------------------------
delaylo equ 0x13 ; DelayCy() subsystem
delayhi equ 0x14 ; DelayCy() subsystem
hours equ 0x15 ; Timer sub
minutes equ 0x16 ; Timer sub
seconds equ 0x17 ; Timer sub
;--< defines >-----------------------------------------------------
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
; K8LH DelayCy() subsystem macro generates five instructions '
; '
clock equ 4 ; 4, 8, 12, 16, or 20 (MHz)
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ clock/4*1000 ; cycles/millisecond multiplier
DelayCy macro delay ; 12..524298 cycle range
movlw high((delay-12)/8)^255
movwf delayhi
movlw low ((delay-12)/8)^255
movwf delaylo
call uDelay-((delay-12)%8)
endm
;******************************************************************
; main.init *
;******************************************************************
org 0x000
Init
movwf OSCCAL ; factory INTOSC calibration
movlw b'00001000' ;
tris GPIO ; GP3 input, all others output
clrf GPIO ; clear output latches
movlw b'10011110' ; 10011110
; 1-------, IOC off
; -0------, weak pullups on
; --0-----, T0CS source Fosc/4
; ---1----, T0SE edge hi>lo
; ----1---, PSA prescale WDT
; -----110, PS prescaler 64
option ; set OPTION reg'
;******************************************************************
; main.loop *
;******************************************************************
cycle
DelayCy(500*msecs) ; burn off 1-sec minus overhead
DelayCy(500*msecs-16) ;
movlw 23 ; 23:59:58 "off" time
btfsc GPIO,0 ; off? yes, skip, else
movlw 0 ; 00:00:02 "on" time
movwf hours ;
movlw 59 ;
btfsc GPIO,0 ;
movlw 0 ;
movwf minutes ;
movlw 57 ;
btfsc GPIO,0 ;
movlw 1 ;
movwf seconds ;
timer
DelayCy(500*msecs-19) ; 1 sec minus 22 cycle loop time
movf GPIO,W ;
xorlw 2 ;
movwf GPIO ; toggle LED on GP1 pin
DelayCy(500*msecs-3) ;
movf GPIO,W ;
xorlw 2 ;
movwf GPIO ; toggle LED on GP1 pin
movlw 59 ; W = 59 (mins/secs reset value)
decf seconds,F ; decrement seconds
btfsc seconds,7 ; negative? no, skip, else
decf minutes,F ; decrement minutes
btfsc seconds,7 ; negative? no, skip, else
movwf seconds ; reset seconds = 59
btfsc minutes,7 ; negative? no, skip, else
decf hours,F ; decrement hours
btfsc minutes,7 ; negative? no, skip, else
movwf minutes ; reset minutes = 59
movf seconds,W ;
iorwf minutes,W ;
iorwf hours,W ; timer timed-out?
skpz ; yes, skip, else
goto timer ; branch
movf GPIO,W ;
xorlw 1 ;
movwf GPIO ; toggle GP0 output
goto cycle ; loop (new cycle)
;******************************************************************
; K8LH DelayCy() subsystem 16-bit "uDelay" timing subroutine *
; *
nop ; (delay-12)%8 == 7 entry point
nop ; (delay-12)%8 == 6 entry point
nop ; (delay-12)%8 == 5 entry point
nop ; (delay-12)%8 == 4 entry point
nop ; (delay-12)%8 == 3 entry point
nop ; (delay-12)%8 == 2 entry point
nop ; (delay-12)%8 == 1 entry point
uDelay incf delaylo,F ; subtract one 8-cycle loop
skpnz ; borrow? no, skip, else
incfsz delayhi,F ; done? yes, skip, else
goto uDelay-3 ; do another 8-cycle loop
retlw 0 ;
;******************************************************************
end