Isaac Marino Bavaresco wrote: > Just make an infinite loop and wait until some pin changes from > low-to-high and high-to-low again (or vice-versa), then increase some > counter (one byte variable). It's not quite that easy. This is apparently a mechanical switch, so it will bounce. Important information the OP left out is what is the maximum frequency of switch closures, and what is the mininum duration of a closure. Since this is apparently a mechanical switch input, we can assume it can be sampled every 1mS. I would set up a periodic interrupt using timer 2 and sample and debounce the switch in the interrupt. The interrupt routine sets a flag on every debounced switch closure. The foreground code can then handle this as another event in the event loop. Dividing by 50 also doesn't sound like the right way. Is it really really 50.00? Probably not. One possibility is to add a small increment into a fixed point gallon accumulator with enough fraction bits. If you want to display whole gallons, you just use the integer bits. Another possibility is to accumulate raw switch closures, then multiply by the appropriate fixed point scale factor to make gallons when needed. Both these methods allow for tweaking the scale factor for calibration. ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist