Gosub to a variable ?
Don Moore
Posts: 4
I'm very new to programming in for the BS2 and have run into a problem. I'm trying to use the GOSUB command but instead of an "address label" I'm trying to get it to read the value of a variable as the address label, and I'm getting an error. "Expected a label"
I'm trying to use it to look up a value to draw with a 7 LED display POV wheel.
I know there's an easier way to do it but the concept is below:
If I can't do it this way, is there a way to pipe my LOOKUP output into the GOSUB command directly instead of a variable (like is done with the OUTH after the lookup for a 7-seg LED)?
Thank you in advance.
~Don
I'm trying to use it to look up a value to draw with a 7 LED display POV wheel.
I know there's an easier way to do it but the concept is below:
If I can't do it this way, is there a way to pipe my LOOKUP output into the GOSUB command directly instead of a variable (like is done with the OUTH after the lookup for a 7-seg LED)?
Thank you in advance.
~Don
displaychar VAR Byte ' Letter to be drawn DO FOR counter = 0 TO 6 LOOKUP counter, [noparse][[/noparse] "A", "B", "C", "D", "E", "F", "G" ], displaychar ' I'm just using this as test data. Later it will be READ from a DATA string, which I'll want to be able to edit for various messages. GOSUB [color=#990000][b]displaychar[/b][/color] PAUSE 10 NEXT LOOP A: OUTH = %0011111 OUTH = %0100100 OUTH = %1000100 OUTH = %0100100 OUTH = %0011111 RETURN . . . G: OUTH = %0111110 OUTH = %1000001 OUTH = %1001001 OUTH = %1001001 OUTH = %0111010 RETURN
Comments
Check out the ON... GOSUB function...
Syntax: ON Offset GOTO Address1, Address2, ...AddressN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Whatever you GOSUB to should be a section of code that eventually executes a RETURN instruction to continue just after your original GOSUB.
GOSUB is like a little side trip for your program. Your program uses GOSUB to take a little side trip, then returns to where it left off, to continue the main journey.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
Change your FOR/NEXT loop to look like this....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I understand that.. but what I'm trying to do is something to the sort of...
MyMessage DATA "This message will be displayed 0" <<--- I want to be able to change this without reworking the entire program
index VAR byte
DO UNTIL displaychar = 0
READ MyMessage + index, displaychar
Gosub displaychar
index = index + 1
loop
And I'm using GOSUB because I may have to jump to the letter E for example several times for my message...
I didn't want to have to hardcode a bunch of GOSUB <address> manually every time I changed the displayed message.
BEAU:
Using the earlier suggestion, I could do a LOOKDOWN on the read "displaychar" to get an offset value (0-25 for A-Z) to use, then specify that on the {ON offset GOTO address1, address2....}. I just thought there might be a more direct approach.
I'll give it a shot to see what I can come up with.
Your new approach will work but it won't allow me to do content checking .. for example .. if the character is a "space" pause for 20ms instead of a GOSUB command. The ABCDE text is just something for me to get started with then build off of
I think I'll have to do your earlier suggestion. The second suggestion you made however, is interesting, and gives me a few ideas for later.
Thanks again.
Post Edited (Don Moore) : 11/9/2008 6:16:10 AM GMT
Your program will be more compact this way, as well.
-Phil