Shop OBEX P1 Docs P2 Docs Learn Events
Global Variables???? — Parallax Forums

Global Variables????

NerdicusMaximusNerdicusMaximus Posts: 11
edited 2007-11-15 15:25 in BASIC Stamp
I am trying to use the polling function to change a variable in my code.

It is my understanding that pollout can put a pin high and pollrun can send you to another file in a multi-file program.

I have tried the pollrun option, but it doesn't bring over my variables for manipulation....

So I tried writing my variable to a place in memory first (Write 1, global) then pollrun to another file, create the same variable in the new file, call it from memory (Read 1, global), manipulate it (global=global + 1) then write it back to the same place (Write 1, global)....

When I return to the original "main" file of my program, it turns out that the address 1 is different for each file in the multi-file program.

Is there a way to call the absolute memory address 1 instead of the relative file memory address?

Maybe there is a way to have pollrun or some other version of polling send me to a different section of my program using a GOTO statement?

Or even better is there a way to make a global variable across the files?

I would appreciate some help here.

B

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-11-14 16:37
    Check out the STORE command in the help files.

    From the help file :- "Designate a program slot for the READ and WRITE instructions to operate upon"

    hope this helps

    Jeff T.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-11-14 19:01
    Each slot is 2k bytes of eeprom, and the WRITE and READ commands by default act within that 2k. STORE, as Jeff points out, allows the program to READ and WRITE to the other 8 or 16 slots. (You do have a BS2p, BS2pe or BS2px, right?--The STORE command is not available in the other Stamps.
    In slot 0:
    x var byte
    x=1
    WRITE 1, x
    RUN 1
    
    In slot 1:
    x var byte
    STORE 0  '<-point to slot 0
    READ 1,x
    DEBUG dec x
    



    Moreover, normal variables like x in the above program carry over unchanged from slot to slot. More corrrectly stated, the physical locations in the 26 bytes of RAM memory carry over, and the variable names in the two slots can be named in the same order in both slots so that they do in fact refer to the same physical locations.

    And again, there is scratchpad RAM in the multibank Stamps, and that carries over globally from slot to slot. So in the above snippet, you could replace WRITE with PUT and READ with GET, and leave out the STORE.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-15 15:25
    Another consideration is how often you’re writing to the EEPROM. The write cycle lifetime of the EEPROM is ~1,000,000 writes before it wears out. Depending on how often you’re writing that could be done in as little as hours or days…

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.