At 02:18 AM 12/30/98 +0300, you wrote: >Hello John. > >Can you explain your brilliant idea with a little example of code ? > >WBR Dmitry. It's been a while since I used PIC assembly language, but how about this: increment: ; increment 16-bit counter incfsz lowbyte,F ; bump low byte of counter return ; quit if done fixhighbyte: rrf highbyte,W ; remove duplicate bit of counter movwf temp ; save for updating incf temp,F ; bump the literal portion of the count rlf lowbyte,W ; get the high bit into the carry rlf temp,W ; put the carry into low bit of high cou nt movwf highbyte ; save for posterity return validate: ; validate 16-bit counter (as at reset) clrf temp ; Get a 0 into our work register rrf highbyte,W ; Move ls bit into high bit of temp rrf temp,F movlw 0x80 ; Strip all bits except high bit of lowb yte andwf lowbyte,W xorwf temp,W ; Does lsb of high == msb of low? btfss Z return ; Yes, back to caller goto fixhighbyte ; No, correct before leaving >> |In all cases of a 16-bit count, the main program has to be sure an >> |interrupt dosen't occur and change the count inbetwwen reading (or >> |writing) the two bytes of the count. >> >> A related problem, but one which needs a different solution, is >> handling counters that need to survive resets and other unpredict- >> able events. One approach that can work well for this is to have >> a 1-bit overlap between bytes in the counter; if the LSB of a byte >> doesn't match the MSB of the byte below, increment the counter. >> >> This approach has the advantage that the counter is never in an >> undetectably-illegal state. When reading the counter, performing >> a normalization on the read value will always produce a correct >> reading no matter when the data is read. > ================================================================== Andy Kunz - Statistical Research, Inc. - Westfield, New Jersey USA ==================================================================