Shop OBEX P1 Docs P2 Docs Learn Events
Problems with gosub — Parallax Forums

Problems with gosub

grungegrunge Posts: 5
edited 2009-01-28 23:28 in BASIC Stamp
Hello, i·want to know how can i use GOSUB in other "unit/project"...

i wanna do something like this (exemple):

'
[noparse][[/noparse]THIS IS UNTITLED1]
' {$STAMP BS2sx, Untitled2.bsx}
' {$PBASIC 2.5}
GOSUB a1


'
[noparse][[/noparse]THIS IS UNTITLED2]
' {$STAMP BS2sx}
' {$PBASIC 2.5}
a1:
DEBUG "xalala"

and i want to know if i can do it with variables like con's and pin's...?

I hope I explained it clearly.
grateful for the attention

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-28 16:53
    The short answer is no.

    You have probably read some about "multi-slot" programs each of which reside in a 2K "slot" in the Stamps with 16K of program memory like the BS2sx. There are no subroutine calls between slots. It is possible to make the slot programs behave somewhat like subroutines, but it takes some work on your part and the GOSUB can't be used. When a program in a new slot is started, it begins at its beginning and there's no memory of where it came from (unless you keep track of that yourself in the programs). There's a document on multi-slot programming that discusses this (Nuts and Volts Column #87 ... Choose the Resources tab from the main Parallax webpage for a link to the index).
  • grungegrunge Posts: 5
    edited 2009-01-28 17:51
    i read a little bit of the document (Nuts and Volts Column #87)
    and if i understand it correctly, this happens only with BS2e, BS2sx, BS2p, right?

    but...if i use BS2PE, i can do what i want or no too?
  • SRLMSRLM Posts: 5,045
    edited 2009-01-28 21:45
    No. The same thing applies for all the stamps with slots. You need to create some sort of system where you store numbers in either SCRAM or EEPROM, and retrieve them in the other program slot to determine what method to call. Take a look at the following code to see an example. It uses the BS2e, but the same thing applies for the BS2sx.

    http://forums.parallax.com/showthread.php?p=741023
  • grungegrunge Posts: 5
    edited 2009-01-28 23:28
    which of the variables you are using in the other "unit"?
    because now as I can't download your code, but later I'm gonna see ... thanks for the tip
Sign In or Register to comment.