Shop OBEX P1 Docs P2 Docs Learn Events
SERIN right into SPRAM — Parallax Forums

SERIN right into SPRAM

MoskogMoskog Posts: 554
edited 2009-01-01 20:40 in BASIC Stamp
While trying to limit the number of varables, to save RAM, I would like to PUT the bytes received by the SERIN command right into locations of the SPRAM.

This is the way I do it today:

firstVariable var word
secondVariable var word
thirdvariable var word

SERIN RX, Baud, [noparse][[/noparse]firstVariable, secondVariable, thirdVariable]

PUT 0, firstVariable
PUT 1, secondVariable
PUT 2, thirdVariable

So, is there a better way to put the values into the SPRAM without spending Words?

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-01 18:54
    Have a look at the SPSTR formatter that's included with the BS2p/pe/px. It's described in the Basic Stamp Syntax and Reference Manual in the chapter on the SERIN statement.
  • MoskogMoskog Posts: 554
    edited 2009-01-01 19:39
    I noticed an error in my example above as the SPRAM locations are byte-sized, even though it doesnt affect my original question, the example should have been:

    firstVariable var word
    secondVariable var word
    thirdvariable var word

    SERIN RX, Baud, [noparse][[/noparse]firstVariable, secondVariable, thirdVariable]

    PUT 0, Word firstVariable
    PUT 2, Word secondVariable
    PUT 4, Word thirdVariable

    Well, thank you Mike for reply, I see the SPSTR formatter in the manual. There isn't much information on the formatter there. I can see what it is, at page 404 (manual 2.2) but I can't find no additional explanation later in the chapter. But I see examples where other formatters are placed within SERIN commands so I guess I should give it a try.
  • MoskogMoskog Posts: 554
    edited 2009-01-01 20:40
    Now I found the solution to the problem:

    SERIN RX, Baud, [noparse][[/noparse]firstVariable, secondVariable, thirdVariable]

    PUT 0, Word firstVariable
    PUT 2, Word secondVariable
    PUT 4, Word thirdVariable

    This can be replaced with the following line:

    SERIN RX, Baud, [noparse][[/noparse] SPSTR 48]

    The SPSTR 48 puts the 3 incoming Words into the SPRAM starting at location 0.
    So I can read the firstVariable.HIGHBYTE out of location 0, firstVariable.LOWBYTE out of location 1 and so on.

    But I won't do that because what I wanted to do was to limit the RAM used for variables to minimum.. but now I can declare just one variable and use it several times.

    Thanks Mike Green for leading me into the right direction (again)!
Sign In or Register to comment.