David VanHorn wrote: > I wasn't clear there, this debouncer takes care of N keys. > A foreground task compares current key state to stored key state, and > re-loads the timer if it detects a change. If the timer goes to 0, then I > save the state of the switches as debounced, and set a bit flag that tells > tasks that there are new switches. > > Key_scan: > ;assuming 8 keys on a port, but could be any number > ;could be multiple ports. David, Your routine appears to handle only 1 switch press at a time. If you want to handle multiple presses and still use debouncing, then here's an AVR version of my debounce routine: ;Increment the vertical counter EOR count_A,count_B COM count_B ;See if any changes occurred IN temp, pina EOR temp, cva ;Reset the counter if no change has occurred AND count_B,temp AND count_A,temp ;If there is a pending change and the count has ;rolled over to 0, then the change has been filtered COM temp ;Invert the changes OR temp, count_A ;If count is 0, both A and B OR temp, count_B ;bits are 0 ;Any bit in temp that is clear at this point means that the input ;has changed and the count has rolled over. COM temp ;Now temp holds the state of inputs that have just been filtered ;to a new state. Update the changes: EOR cva, temp ;leave with temp holding the state of all filtered bits that have ;change state RET cva, count_A, count_B and temp are all in register memory. Scott PS This is the first AVR program I've ever "written". But I really just babelfished PIC into AVR and may've made a mistake. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist