' ========================================================================= ' File....... SW21-EX14-Debounce.SXB ' Purpose.... Simple digital clock with software multiplexing ' Author..... (C) 2000 - 2005, Parallax, Inc. ' E-mail..... support@parallax.com ' Started.... 01 SEP 2005 ' Updated.... 23 MAR 2007 by TSaavik for SX28 ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' This program demonstrates the simultaneous debouncing of multiple inputs. ' The input subroutine is easily adjusted to handle any number of inputs. '------{ Device Settings ]------------------------------------------------- DEVICE SX28,TURBO,BANKS8,OSCHS3,SYNC,OPTIONX FREQ 50_000_000 ID "EX14" IRC_CAL IRC_SLOW ' -----[ I/O Definitions ]------------------------------------------------- BtnBus VAR RB ' four inputs, pins 0 - 3 ' -----[ Constants ]------------------------------------------------------- ' -----[ Variables ]------------------------------------------------------- btns VAR Byte ' debounced inputs idx VAR Byte ' loop counter ' -----[ Initialization ]------------------------------------------------- PROGRAM Start watch btns, 4, UBIN ' -----[Subs ]------------------------------------------------------------- ' -----[ Program Code ]---------------------------------------------------- Start: Tris_B = %00001111 ' make 0-3 inputs Main: DO GOSUB Get_Buttons ' get debounced inputs 'DEBUG HOME, ' "Inputs = ", IBIN4 btns ' display in binary mode BREAK ' use "polling" mode to read btn state PAUSE 50 LOOP ' -----[ Subroutines ]----------------------------------------------------- Get_Buttons: btns = %1111 ' enable all four inputs FOR idx = 1 TO 5 btns = btns & ~BtnBus ' test inputs PAUSE 5 ' delay between tests NEXT RETURN