2010/3/21 PICdude : > This is what I figure is happening here... All math is being done in > packed BCD format, so when the seconds go from 0x09, then next value > should be 0x10. =A0But incrementing will take 0x09 to 0x0A, so he tests > to see if that BCD-clock rollover point has reached the 'A' in the > right digit by adding '6', which would take it to 0x10. =A0If adding 6 > does roll it over, the DC bit is set, and this is his indication to > leave it alone now. =A0DC is actually Digit Carry, and gets set when the > lower nibble overflows. =A0IIRC it does not work for incf, but for addwf > it does. =A0The instruction set section of the datasheets tell you which > instructions affect which status bits, and this explains those bits > better... http://www.pictutorials.com/The_Status_Register.htm > > Back to the code, if adding 6 does not cause the digit carry, then he > undoes the 6-addition. > > Now for the rightmost seconds digit, the test value is 6, but for > leftmost digit of the seconds, the rollover point is when the '5' in > 0x59 changes to a '6' (as in 0x60). =A0To test for that, he temporarily > adds whatever will cause 0x60 to rollover to 0x100 (to set the carry > flag), and rather than doing the math, my guess is that it's somewhat > self-commenting to use '0x100 - 0x60'. Ah, now I get more of it. Thank you for the excellent explanation! I think I'm probably going to write my own code. It won't be nearly as efficient as Andrew's but at least I'll be able to understand it! I might actually make mine unpacked as it might make things a bit easier for display. I've got plenty of free registers so I'm not too concerned about saving one or two. Thanks! Josh -- = A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -Douglas Adams -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist