Cesare Lavazza wrote: > > (A newbie question) > > I need a very small routine for debouncing a switch. > The PIC model is 16C84. Thanks. > > Bye. You need 1 byte an 1 bit of RAM. Call it DebounceCount (byte) and Input_1_Debounced (bit). Use timer 0 to interrupt every 20ms or so. In the interrupt routine, check to see if the input is at the state you want. If it is not, clear counter DebounceCount. If the input is at the state you want, increment DebounceCount. Check now to see if DebounceCount is greater than, say 15. If it is not, just jump out of the interrupt service routine. If DebounceCount is greater than 15, set flag Input_1_Debounced. In your main routine, you only have to check if Input_1_Debounced is set. It may seem like more work than scan-wait-scan methods, but it will simplify your main code considerably. PS. If RAM is at a premium, you can use one of the bits of DebounceCount, say bit 4, as the flag. -- Friendly Regards Tjaart van der Walt mailto:tjaart@wasp.co.za _____________________________________________________________ | Another sun-deprived R&D Engineer slaving away in a dungeon | | WASP International http://wasp.co.za | | GSM and GPS value-added applications | | Voice : +27-(0)11-622-8686 | Fax : +27-(0)11-622-8973 | |_____________________________________________________________|