Andres Djordjalian wrote: > > > From: Shane Nelson > > Subject: clock code challenge: > > Hi, > > After having seen the amazing results from other code challenges > > I thought I would try putting one out there myself. > > The goal is to have a routine that increments and keeps track of > > time in a BCD format. > > Points are scored as follows: > > 1 point for each ROM location used. > > 3 for each RAM. > > ; BCD clock code challenge > ; WARNING: This code is not tested > ; > ; The regs must be allocated so that a certain bit is set only for > ; the hours, for example: > > seconds EQU 20 > minutes EQU 21 > hours EQU 22 > #define hoursFlag FSR,1 > > ClockTick: MOVLW seconds > loop: MOVWF FSR > INCF INDF,f > MOVLW 6 Actually, the next two lines should be deleted. You don't want to check for 3 rolling over to 4 if this is the hour's pass through the loop. Especially since the roll over from 23 to 24 is checked a few lines below. > xxxxxxxxxxxxxx BTFSC hoursFlag > xxxxxxxxxxxxxx MOVLW 11 > ADDWF INDF,f > BTFSS STATUS,DC > SUBWF INDF,f > MOVLW 60 > BTFSC hoursFlag > MOVLW 24 > SUBWF INDF,W > BTFSS STATUS,C > RETURN > CLRF INDF > INCF FSR,W > BTFSS hoursFlag > GOTO loop > ; This last instruction is not necessary if the code that's executed > ; after the routine follows, in that case the "RETURN" of a fwe lines > ; above should be a "GOTO..." > RETURN