Program Listing ;******************************************************************************
;       Software Time Clock
;
;
;       Length: 28/50/56 bytes (depending upon clock type, +1 for bank select)
;       Author: Craig Webb
;       Written: 98/8/17
;
;
This program implements a software time clock virtual peripheral ; that keeps a 16 bit count of elapsed time in milliseconds. ; The option is available to include seconds, minutes, hours and even ; days to this clock if desired. ; The code takes advantage of the SX's internal RTCC-driven interrupt ; to operate in the background while the main program loop is executing. ;
;******************************************************************************
;
;****** Assembler directives
;
; uses: SX28AC, 2 pages of program memory, 8 banks of RAM, high speed osc.
;       operating in turbo mode, with 8-level stack & extended option reg.
;
DEVICE  pins28,pages2,banks8,oschs
DEVICE  turbo,stackx,optionx
ID      'TimeClck'
;program ID label RESET   reset_entry ;set reset/boot address ;
;******************************* Program Variables ***************************
;
;****** Program Parameters
;
;clock_type
= 0 ;16 bit msec count only clock_type = 1 ;include sec, min, hours ;clock_type = 2 ;include day counter ;
;****** Program Constants
;
tick_lo
= 80 ;50000 = msec instruction count tick_hi = 195 ; for 50MHz, turbo, prescaler=1 ;
int_period
= 163 ;period between interrupts ;
mspersec_hi
= 1000/256 ;msec per second hi count mspersec_lo = 1000-(mspersec_hi*256)  ;msec per second lo count ;
;****** Register definitions
;
org 8 ;start of program registers main            = $ ;main bank ;
temp            ds
1 ;temporary storage ; org 010H ;bank0 variables clock EQU $ ;clock bank ;
time_base_lo
DS 1 ;time base delay (low byte) time_base_hi DS 1 ;time base delay (high byte) msec_lo DS 1 ;millisecond count (low) msec_hi DS 1 ;millisecond count (high) IF clock_type>0 ;do we want sec, min, hours? seconds DS 1 ;seconds count minutes DS 1 ;minutes count hours DS 1 ;hours count