In general, I don't like to tie things like this to code execution speed, so I use a timer to generate a 1mS system int and drive all the events at 10mS and larger timing from that. So in keyboard scanning, when I see a change on the inputs at the hardware level, I load a byte in SRAM with the debounce time. If I see another change, I reload the byte. The 1mS tick int decs that byte to 0. If the byte gets to 0, then I update the image of the keyboard, and signal in a bit that the keyboard has changed. When the key routine picks up the information, it clears this bit, which prevents it from seeing a single long press as multiple single presses (and provides a way to do auto-repeat) -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist