In SX Microcontrollers, SX/B Compiler and SX-Key Tool, ALTITUDEAP wrote: Thanks Bean This is what i now have. [code] DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Keys VAR RC ' keyboard scan port TRIS_Keys VAR TRIS_C PLP_Keys VAR PLP_C Col1 VAR Keys.7 ' column inputs Col2 VAR Keys.6 Col3 VAR Keys.5 Col4 VAR Keys.4 Restart Var RA.1 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Yes CON 0 ' active low input No CON 1 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- theKey VAR Byte ' from keypad, 0 - 16 oldKey VAR Byte ' Temp used by GET_KEY routine row VAR Byte ' keyboard scan row tmpB1 VAR Byte ' subroutine work vars tmpB2 VAR Byte tmpW1 VAR Word VendStatus Var Word VendAmm Var byte (16) i Var byte LastKey VAr byte key VAR Byte ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- GET_KEY SUB 0 ' get key from pad DELAY SUB 1, 2 ' delay in milliseconds ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: lastKey = 16 PUT vendAmm, 25, 25, 25, 25, 25, 25, 25, 25, 25, 20, 20, 20, 15, 15, 10, 10 Main: DO key = GET_KEY IF key <> 16 THEN IF key < 16 THEN tmpB1 = 1 SHL Key ENDIF tmpW1 = 1 SHL Key DEC VendAmm(key) IF vendAmm(key) = 0 THEN VendStatus = VendStatus OR tmpW1 ENDIF '---------Reseting the Flags that indicate empty vend merchandise ENDIF Break IF Restart = 0 then goto start Endif LOOP END ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- ' This routine works by activating each row, then scanning each column. ' If a particular row/column junction is not active (pressed), the key ' value is incremented and the scan continues. As soon as a key is found, ' the routine exits. If no key is pressed the routine will exit with a key ' value of 16. 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 thekey = tmpB1 IF thekey = 16 THEN IF lastKey <> 16 THEN thekey = lastKey lastKey = 16 RETURN thekey ENDIF ENDIF lastKey = thekey RETURN 16 ' ------------------------------------------------------------------------- ' Use: DELAY ms ' -- 'ms' is delay in milliseconds, 1 - 65535 DELAY: IF __PARAMCNT = 1 THEN tmpW1 = __PARAM1 ' save byte value ELSE tmpW1 = __WPARAM12 ' save word value ENDIF PAUSE tmpW1 RETURN [/code] Man i love the SX Debug feature. As i press and hold the button i can see that the SX has noticed the state change of the switch and then just as i release it, it DEC the value in associated register. What i cant seem to make it show me is the Value for VendStatus. Should i be able to see that in the register somewhere. Maybe my code is not making the bit in the associated location go high. ie if the value in register 2 goes to 0 the Value in VendStatus should be 0000_0000_0000_0100 ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=151224#m153768 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)