In SX Microcontrollers, SX/B Compiler and SX-Key Tool, skynugget wrote: JohnnyMac you rock! thanks! I have always had problems with bit masks till now. I really wasn't concerned about space for this stage of the project, i just need to get it built and working. As I have time I would like to incorporate the ISR code from the Mo MIDI project to get status from the device, so it puts me a leg up. (If i can ever get the manual) Here's the updated code that does the exact same thing above. Hope someone learns something about those fancy bitmasks! [code] DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42 FREQ 20_000_000 ID "BTN2MIDI" ' ------------------------------------------------------------------------- ' I/O Pins ' ------------------------------------------------------------------------- TX PIN RA.1 INPUT Btns PIN RB input PULLUP SCHMITT LEDS PIN RC output ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Baud CON "OT31250" ' for MIDI Channel CON 0 CtrChange CON $C0 | Channel ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- tmpB1 VAR Byte ' for subs/funcs tmpB2 VAR Byte tmpW1 VAR Word tmpBtns VAR Byte idx VAR Byte mask VAR Byte check VAR Byte ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine / Function Declarations ' ------------------------------------------------------------------------- WAIT_MS SUB 1, 2 ' replaces PAUSE TX_BYTE SUB 1 ' transmit a byte TX_STR SUB 2 ' transmit a string CNG_PGM SUB 1 ' Change MIDI program GET_BTNS FUNC 1, 0, 0 ' Poll for button press ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: Main: tmpBtns = GET_BTNS IF tmpBtns = %00000000 THEN Main ' wait for button press FOR idx = 0 TO 5 ' loop through six buttons mask = 1 << idx ' create mask for input check = tmpBtns & mask ' test the button IF check > 0 THEN ' was button pressed? CNG_PGM idx ' yes, change selected program wait_ms 1000 ' pause for load time on device leds = mask ' light its LED DO tmpBtns = GET_BTNS LOOP UNTIL tmpBtns = %00000000 ' force release of all buttons GOTO Main ENDIF NEXT GOTO Main ' loop ' ------------------------------------------------------------------------- ' Subroutine / Function Code ' ------------------------------------------------------------------------- ' Use: WAIT_MS duration SUB WAIT_MS IF __PARAMCNT = 1 THEN tmpW1 = __PARAM1 ELSE tmpW1 = __WPARAM12 ENDIF PAUSE tmpW1 ENDSUB ' ------------------------------------------------------------------------- ' Use: TX_BYTE aByte SUB TX_BYTE SEROUT TX, Baud, __PARAM1 ENDSUB ' ------------------------------------------------------------------------- ' Use: TX_STR [String | Label] ' -- moves z-String to tx buffer ' -- "String" is an embedded string ' -- "Label" is a DATA label with z-String SUB TX_STR tmpW1 = __WPARAM12 ' get address of start DO READINC tmpW1, tmpB1 ' read a character IF tmpB1 = 0 THEN EXIT ' done? TX_BYTE tmpB1 ' no, transmit the char LOOP ENDSUB ' ------------------------------------------------------------------------- ' Use: CNG_PGM program# SUB CNG_PGM tmpB1 = __PARAM1 TX_BYTE CtrChange ' Control Change TX_BYTE tmpB1 ' Program Number ENDSUB ' ------------------------------------------------------------------------- ' Use: var = GET_BTNS FUNC GET_BTNS gbIdx VAR tmpB1 gbResult VAR tmpB2 gbResult = %11000000 ' bit 6,7 not used, assume pressed FOR gbIdx = 1 TO 25 ' 25ms debounce WAIT_MS 1 gbResult = gbResult | RB ' scan inputs NEXT GbResult = gbResult ^ $FF ' invert (1 = pressed) RETURN gbResult ENDFUNC ' ------------------------------------------------------------------------- [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=394524#m395079 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)