PIC Microcontoller Time Method

Count Seconds, Minutes, and Hours by Andrew Warren

SECONDS EQU [any register, on any page] 
MINUTES EQU SECONDS+1 
HOURS   EQU MINUTES+1 

TICK: MOVLW SECONDS       ;First, initialize the FSR to point 
     MOVWF FSR           ;  at SECONDS.
     CALL  SUB1          ;Use the BCD-increment code to inc
     CALL  SUB0          ;  SECONDS and then MINUTES.
     CALL  SUB0          ;Call it one last time to increment
                         ;  HOURS.
     GOTO  SUB2          ;Keep HOURS in the range [0-23].

SUB0: INCF  FSR           ;You enter here to point to the next 
     SKPNC               ;  register before incrementing it.
SUB1: INCF  INDF          ;Or enter here to just increment the
                         ;  register. 
     MOVLW 6             ;Use this MOVLW/ADDWF to see whether
     ADDWF INDF          ;  reg is outside the range [0-9].
 
     SKPDC               ;Obscure DC flag usage was contributed
     SUBWF INDF          ;  by Scott Dattalo.
     MOVLW 0100H - 060H  ;Load W with a value that'll make the
SUB2: ADDWF INDF,W        ;  ADDWF overflow if the reg > 60.
     SKPNC               ;If there's an overflow, clear the
     CLRF  INDF          ;  register.
     RETLW 0100H - 024H  ;Now return with W holding a value that
                         ;  will make ADDWF overflow if reg>24.