Shop OBEX P1 Docs P2 Docs Learn Events
multiple programs — Parallax Forums

multiple programs

electromanjelectromanj Posts: 270
edited 2010-01-20 04:15 in BASIC Stamp
Hello, I have a question about running multiple programs on a bs2SX. Do variables transfer from one program to another? Do I need to declare the variable in every new program?

Example:

Program 0
' {$STAMP BS2sx,program1.bsx}
' {$PBASIC 2.5}
LED var byte
DEBUG· "Please enter·LED 1-4 ---> "
DEBUGIN DEC1 LED
RUN 1

Program 1
' {$STAMP BS2sx}
' {$PBASIC 2.5}
LED var byte
if LED=1 then high 1
if·LED=2 then high 2
if LED=3 then high 3
if LED=4 then high 4

·

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2010-01-20 00:59
    There's some good information on this in the BS2 help file section on the RUN command.
    BS2 Help File Gremlin said...

    The I/O pins retain their current state (directions and output latches) and all Variable and Scratchpad RAM locations retain their current data during a transition between programs with the RUN command. If sharing data between programs within Variable RAM, make sure to keep similar variable declarations (defined in the same order) in all programs so that the variables align themselves on the proper word, byte, nibble and bit boundaries across programs. The following programs illustrate what happens with mismatched variable declarations:

    I'd say you probably want to read that part of the help file carefully. It looks like not only do you have to redeclare the variables, you have to be very careful about how you do so.
  • electromanjelectromanj Posts: 270
    edited 2010-01-20 01:43
    Thank You Very Much!

    I will read that help file. I also came across a similar post about more EEPROM a little further down the page, with a reference to Nuts and Volts article #87. (Thank you Mike Green). I am reading that also.

    Upon further reading of the help file it appears that you can transfer var between programs as long as you define them in the right order.

    If you defined them all as words in the same order they would transfer correctly. Is this right?
  • JDJD Posts: 570
    edited 2010-01-20 02:00
    Electromanj,

    Yes that is correct, you can use the same variables across the slots. Here is a little sample that puts a value in a var and then goes to another slot to display it. Hope this helps

    I used the BS2sx, but you could do the same with any of the multi-slot BASIC Stamp 2 modules. If you open temp0.bsx it will open temp1.bsx automatically.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • electromanjelectromanj Posts: 270
    edited 2010-01-20 02:33
    What a great company and what a great support community!!!!!!!!!!!!!!!

    I have one more question on this subject.
    If you have more than one variable, does it matter what order you put the variables in the different slots?
    Example:

    Program 0
    LED var word
    SETPOINT var word

    Program 1
    SETPOINT var word
    LED var word
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-01-20 03:51
    The variables have to be defined in the same order. Think of absolute memory locations. Operations on SETPOINT in slot 1 will affect the memory location that is called LED in slot zero. So when the program switches back to slot zero, the value in finds in LED will not be what is expected. Ditto for the other crossed "wires".

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 1/20/2010 4:32:24 AM GMT
  • electromanjelectromanj Posts: 270
    edited 2010-01-20 04:15
    OK. I think I got it.

    Thanks to everyone for all the help!!!!!!!!!!!!!!

    P.S. Thanks for keeping the explanations simple. They were really easy to understand.
Sign In or Register to comment.