ENDIF IF clock_type>1 ;do we want day count? days DS 1 ;days count ENDIF ;
;*************************** INTERRUPT VECTOR ******************************
;
; Note: The interrupt code must always originate at 0h.
;
A jump vector is not needed if there is no program data that needs ; to be accessed by the IREAD instruction, or if it can all fit into ; the lower half of page 0 with the interrupt routine. ; ORG     0 ;interrupt always at 0h ; JMP interrupt ;interrupt vector ;
;**************************** INTERRUPT CODE *******************************
;
; Note: Care should be taken to see that any very timing sensitive routines
;       (such as adcs, etc.) are placed before other peripherals which has
;
varying execution rates (like the software clock, for example). ;
interrupt
;beginning of interrupt code ;
;****** Virtual Peripheral: Time Clock
;
; This routine maintains a real-time clock count (in msec) and allows processing
; of routines which only need to be run once every millisecond.
;
;
Input variable(s) : time_base_lo,time_base_hi,msec_lo,msec_hi ; seconds, minutes, hours, days ; Output variable(s) : msec_lo,msec_hi ; seconds, minutes, hours, days ; Variable(s) affected : time_base_lo,time_base_hi,msec_lo,msec_hi ; seconds, minutes, hours, days ; Flag(s) affected : ; Size : 17/39/45 bytes (depending upon clock type) ; + 1 if bank select needed ; Timing (turbo) : [99.9% of time] 14 cycles ; [0.1% of time] 17/39/45 cycles (or less) ; + 1 if bank select needed ;
;
BANK clock ;select clock register bank MOV W,#int_period ;load period between interrupts ADD time_base_lo,W ;add it to time base SNC ;skip ahead if no underflow INC time_base_hi ;yes overflow, adjust high byte MOV W,#tick_hi ;check for 1 msec click MOV W,time_base_hi-W ;Is high byte above or equal? MOV W,#tick_lo ;load instr. count low byte SNZ ;If hi byte equal, skip ahead MOV W,time_base_lo-W ;check low byte vs. time base SC ;skip ahead if low JMP :done_clock ;If not, end clock routine :got_tick CLR time_base_hi ;Yes, adjust time_base reg.'s SUB time_base_lo,#tick_lo    ; leaving time remainder INCSZ msec_lo ;And adjust msec count DEC msec_hi ; making sure to adjust high INC msec_hi ; byte as necessary IF clock_type>0 ;do we want sec, min, hours? MOV W,#mspersec_hi ;check for 1000 msec (1 sec tick) MOV W,msec_hi-W ;Is high byte above or equal? MOV W,#mspersec_lo ;load #1000 low byte SNZ ;If hi byte equal, skip ahead MOV W,msec_lo-W ;check low byte vs. msec count SC ;skip ahead if low