On Sat, 20 Sep 1997 06:52:50 -0400 Steve Smith writes: >Below is a section of code that reads 32 inputs into an '84 via >hc244's I >wass origanally having trouble with bouncy switches but after adding >Scott's >debounce chunk it wont work at all can sombody please help this is >causing >lots of grey hairs and a severly short temper. DTA is port_b and the >information is saved in four consecutive registers. >TIA Steve..... > > The debounce code is based on the premise that while the switch is bouncing it won't read the same 4 times in a row. Counters that count from 0 to 3 are used for each switch to save how many times it has read the same. These counts are stored in GP2 and GP3, the low bits in GP3 and the high bits in GP3. These two bytes must be preserved between calls to the routine. Each pair of counter bytes holds 8 counters. Since you're using 32 switches you need four sets of 8 counters. Unless you're really strapped for code space, the simplest way to do this is with 4 copies of the debounce routine, accessing different pairs of bytes in RAM. Another potential problem comes from Scott's debounce code needing to read DTA twice. Since you're pointing DTA directly at port B, it may not read the same both times. I dodn't look at the code closely enough to see if that would make it malfunction, but it seems that it would be a problem. You should read PORTB only once per set of 8 switches then copy it to a temporary location for the debounce routine. Also the last accepted states of the switches (in INDIRECT) need to be preserved between calls. I've had good results rejecting switch bounce by simply reading the switches at intervals longer than the bounce time (from 10 to 40 ms depending on the switch). A transition of the switch will only register once, even if one of the reads is while the switch is bouncing.