Code:
;******************************************************************
;* *
;* *
;* MPLAB: 8.50 (tabs=8) *
;* MPASM: 5.35 *
;* *
;******************************************************************
radix dec
include "p10f200.inc"
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF
;--< variables >---------------------------------------------------
delaylo equ 0x10 ; DelayCy() subsystem
delayhi equ 0x11 ; DelayCy() subsystem
hours equ 0x12 ; Timer sub
minutes equ 0x13 ; Timer sub
seconds equ 0x14 ; 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.startup *
;******************************************************************
org 0x000
Startup
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 *
;******************************************************************
; alternate 00:00:02 GP0 = 1 (on) and 23:59:58 GP0 = 0 (off)
;
cycle
DelayCy(500*msecs) ;
DelayCy(500*msecs-16) ;
movlw 23 ; 23 hours
movwf hours ;
movlw 59 ; 59 minutes
movwf minutes ;
movlw 57 ; 58 seconds
btfsc GPIO,0 ; GP0 off? yes, skip, else
movlw 1 ; 2 seconds
movwf seconds ;
btfsc GPIO,0 ; GP0 off? yes, skip, else
clrf minutes ;
btfsc GPIO,0 ; GP0 off? yes, skip, else
clrf hours ;
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
Bookmarks