View Full Version : 255 GoSub Limit?
04-14-2007, 06:06 PM
I hit a limit aparently. Tells me the limit of 255 GOSUBs was exceeded. Is this a language limitation or a BS2 limitation? I also have a BS2sx if maybe it will allow more GOSUBs.
04-14-2007, 07:48 PM
It is a PBASIC Language restriction. Sounds like combining some routines might be in order.
04-14-2007, 11:36 PM
You have more than 255 subroutines in 2000 bytes of program memory? That's amazing.
04-15-2007, 01:07 AM
Yes, I am trying to write a program that will basically do a LED light sequence that is about 1000 steps long. I got like 25% of the way through programming the squence and hit the limit. I'm not sure this is going to be possible anymore. I was doing something like this:
< etc, etc... >
LEDs = %00000001
< other functions for other lights B-D >
This is just kind of how the code was working, but then I hit the 255 max. I was doing it this way because I guess I dont have enough variable or eeprom memory to store the order of light flashes.
Anyone know how I can do this? There is going to be potentially 800-1200 light flashes that need to happen. The time between the flashes may change as well, if you look in my example sometimes it waits 150ms and sometimes 100ms
04-15-2007, 01:10 AM
Also worth mentioning is that the subroutines such as blink_light_A also have other stuff inside them, so I can't simply replace the GOSUB call with the LEDS = %00000001 line without getting extremely messy.
04-15-2007, 01:30 AM
Without seeing all the code its hard to give a full answer but from what we have I can see ways of trimming it down some.
The Leds don't have to be in a subroutine just give them a variable in your main loop
do the same with the pause you might even use the same variable if you don't need to retain it
If the subroutines are doing similar functions try and do it all with one subroutine but pass it different paramaters
04-15-2007, 03:46 AM
Yup, this just cries out for using a 'temp' variable.
MyTemp = 1
MyTemp = 2
GOTO MAIN ' Also known as, "the main loop"
IF MyTemp = 1 THEN
IF MyTemp = 2 THEN
This is the 'classic' way to begin 'parameterizing' subroutine calls. It makes life MUCH easier if "DoStuff" and "DoOtherStuff" are quite similar.
Looking at your code, you could have two calls -- long blink and short blink, and set a number of which LED to blink as a 'parameter'.
Another way to do this would be with DATA statements -- a duration, and the LED pattern.· Then your program becomes very simple.
MaxPat = 800
LEDPat = 0
··READ LEDPat, TimeVal
· READ LEDPat + 1, LEDVal
· GOSUB BlinkLED· ' (TimeVal, LEDVal)
· LEDPat = LEDPat + 2
· IF LEDPat > MAXPat THEN
··· LEDPat = 0
· END IF
· GOTO MAIN
· LEDS = LEDVal
· PAUSE TimeVal
DATA 100, $01, 150, $02, 'etc -- you'll have to input the pattern of LED blinks,
' but it will be WAY shorter than typing in 800 "LED = xxx: PAUSE 100" statements.
Post Edited (allanlane5) : 4/14/2007 7:54:35 PM GMT