Help converting CASE SELECT to IF THEN ELSE statements (BS2 to SX/B)
T&E Engineer
Posts: 1,396
I am trying to convert this routine from a BS2 to SX/B:
Main:
DO
· GOSUB getkey
· 'DEBUG TAB,HEX3 scancode
· IF scancode<$FF THEN
··· SELECT scancode
····· CASE $12,$59
······· shiftbit=~F0bit
······· F0bit=0
······· ascii=0
····· CASE $E0·· 'extended key
········· ascii=0
····· CASE $F0· 'erase key release
······· F0bit=1
······· ascii=0
····· CASE >143
······· ascii=0
····· CASE ELSE
······· IF F0bit=0 THEN READ (144 * shiftbit + scancode),ascii
······· F0bit=0
··· ENDSELECT
··· IF ascii > 0 THEN DEBUG ascii
· ENDIF
LOOP
The SELECT and CASE Statements are getting a bit hairy on the IF THEN conversion.
Any help would be appreciated. I understand that the GOSUB keyword statement needs to be removed and that DEBUG needs to be removed too.
Thanks.
Main:
DO
· GOSUB getkey
· 'DEBUG TAB,HEX3 scancode
· IF scancode<$FF THEN
··· SELECT scancode
····· CASE $12,$59
······· shiftbit=~F0bit
······· F0bit=0
······· ascii=0
····· CASE $E0·· 'extended key
········· ascii=0
····· CASE $F0· 'erase key release
······· F0bit=1
······· ascii=0
····· CASE >143
······· ascii=0
····· CASE ELSE
······· IF F0bit=0 THEN READ (144 * shiftbit + scancode),ascii
······· F0bit=0
··· ENDSELECT
··· IF ascii > 0 THEN DEBUG ascii
· ENDIF
LOOP
The SELECT and CASE Statements are getting a bit hairy on the IF THEN conversion.
Any help would be appreciated. I understand that the GOSUB keyword statement needs to be removed and that DEBUG needs to be removed too.
Thanks.
Comments
I have found that those work better as a replaement for select case, over if then statements.
Look at the sx/b help file for examples on lookup and lookdown.
If you still don't see how those can be used, post here again what you came up with, and I can help you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Meh. Nothing here, move along.
Update: It turns out not to be that bad -- I left plenty of whitespace to make it easy to read:
Post Edited (JonnyMac) : 2/7/2007 1:55:30 AM GMT
I have the program attached and I followed the SX Template.
Any Help. Also if my IF THEN portion looks wrong then I will attemp a LOOKDOWN approach. I like this approach too - but I don't want to change it if I get no compile errors on this section.
Very weird. See attached.
Other notes:
-- Using OUTPUT with the PIN directive takes care of the TRIS register for you (so you don't need the TRIS = %00000000 line)
-- You're using INPUT with a variable; are you trying to float a pin pointed to by that variable?
-- With the TRIS register set you don't need to use HIGH and LOW; just do ThePin = 1 or ThePin = 0 (saves a bit of code space)
-- On your SUB definition, set the parameters count to 0; this will save a bit of code
-- You need to identify your tables with labels as data storage does not start a address 0 as does the BASIC Stamp
-- READ needs the starting addess of table, plus and offset. Use one of the labels from above and add the calculated offset.
Post Edited (JonnyMac) : 2/7/2007 6:10:23 PM GMT
Great analysis! All is·compiling except for the SHIFTIN statement - once I incorporated your comments. Thank you so much!!
SHIFTIN datain, clock, MSBPRE, [noparse][[/noparse]scancode]
ERROR is: BYTE VARIABLE EXPECTED "[noparse][[/noparse]scancode]"
Any ideas?
Thanks again.
SHIFTIN datain, clock MSBPRE, scancode
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
I am out on business travel in Indianapolis for the next couple of days but I will try this code when I get back over the weekend. It looks like it wasn't too hard to convert it from BS2 to SX/B with everyone's great help!
Thanks again to all!
Tim