On Mar 20, 2010, at 9:14 PM, Josh Koffman wrote: > SKPDC is "skip if yes carry"? No, SKPDC is "Skip if Digit Carry" (carry from the low 4 bits.) This code relies on the fact that INCF and CLRF do not affect the Carry bit(s) on PIC16; you'd need to make changes to get it to work on PIC18 or other CPUs... SECONDS EQU [any register, on any page] MINUTES EQU SECONDS+1 HOURS EQU MINUTES+1 TICK: MOVLW SECONDS MOVWF FSR CALL SUB1 ;inc seconds, wrap at 60 (maybe set C) CALL SUB0 ;maybe inc minutes, wrap at 60. (maybe set C) CALL SUB0 ;maybe inc hours, wrap at 60. GOTO SUB2 ; wrap hours at 24 rather than 60! (maybe set C) SUB0: INCF FSR ;go to next digit pair SKPNC ; skip if C previously set ;;; SUB1 increments a BCD register @INDF, unless the first instruction ;;; is skipped, in which case it will end up doing nothing. SUB1: INCF INDF ;increment low nibble MOVLW 6 ;if low nibble is >= 10, this will ADDWF INDF ; wrap it around and inc the high nibble SKPDC ; while causing a "digit carry." SUBWF INDF ;otherwise, undo the add. MOVLW 0100H - 060H ;this does something similar to wrap the ;;; Falls through ;;; SUB2 wraps @INDF based on value in W. SUB2: ADDWF INDF,W ;upper nibble at 6. 0x6x + 0x4x will cause SKPNC ; a carry and.. CLRF INDF ; we'll wrap both nibbles to zero. ;Note that C remains set based on the ADDWF RETLW 0100H - 024H ; set up for wrapping 24 rather than 60. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist