In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote: [code] [code] [code] key VAR Byte oldKey VAR Byte ' Temp used by GET_KEY routine tmpB1 VAR Byte ' Temp used by GET_KEY routine lastKey VAR Byte ' Used by GET_KEY routine, DO NOT USE IN MAIN CODE thisKey VAR Byte ' Used by GET_KEY routine, DO NOT USE IN MAIN CODE Start: lastKey = 16 DO key = GET_KEY IF key <> 16 THEN ' Do whatever ENDIF ' Do other processing LOOP END GET_KEY: oldKey = $FF DO tmpB1 = 0 ' reset keyboard value Keys = %0000_0111 ' activate first row TRIS_Keys = %1111_0000 ' refresh IO state PLP_Keys = %0000_1111 ' pull-up input pins FOR tmpB2 = 1 TO 4 ' scan four rows IF Col1 = Yes THEN EXIT ' check buttons on column INC tmpB1 ' update key value IF Col2 = Yes THEN EXIT INC tmpB1 IF Col3 = Yes THEN EXIT INC tmpB1 IF Col4 = Yes THEN EXIT INC tmpB1 Keys = Keys >> 1 ' select next row Keys = Keys | %0000_1000 ' clear previous row NEXT IF tmpB1 = oldKey THEN EXIT PAUSE 20 oldKey = tmpB1 LOOP thisKey = tmpB1 IF thisKey = 16 THEN IF lastKey <> 16 THEN thisKey = lastKey lastKey = 16 RETURN thisKey ENDIF ENDIF lastKey = thisKey RETURN 16 Try this... Bean. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=151224#m153607 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)