Shop OBEX P1 Docs P2 Docs Learn Events
How to read and display Word value from EE? — Parallax Forums

How to read and display Word value from EE?

ArchiverArchiver Posts: 46,084
edited 2003-06-09 16:00 in General Discussion
I want to store a decimal value in EEPROM and later show it using
DEBUG. Since the number is "large", I need to use Word.
But when I run this below, I don't get 4321, but 225.
What is going on? I'm using PBasic 2.5.

Does anyone know how to read a Word decimal value from EEPROM and
later show it as decimal using DEBUG?

Much thanks in advance.

'{$STAMP BS2}
'{$PBASIC 2.5}

eep VAR Word 'EE pointer
sum VAR Word 'variable used to store data read from EE

data1 DATA Word 4321 'EE data

eep = data1 'point to EE address
READ eep, sum 'read it into sum
DEBUG "number is ", DEC sum, CR 'I want to display sum as decimal!!!

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-06-09 14:13
    At 11:42 AM 6/9/03 +0000, basicstampede wrote:
    >I want to store a decimal value in EEPROM and later show it using
    >DEBUG. Since the number is "large", I need to use Word.
    >But when I run this below, I don't get 4321, but 225.
    >What is going on? I'm using PBasic 2.5.
    >
    >Does anyone know how to read a Word decimal value from EEPROM and
    >later show it as decimal using DEBUG?
    >
    >Much thanks in advance.
    >
    >'{$STAMP BS2}
    >'{$PBASIC 2.5}
    >
    >eep VAR Word 'EE pointer
    >sum VAR Word 'variable used to store data read from EE
    >
    >data1 DATA Word 4321 'EE data
    >
    >eep = data1 'point to EE address
    >READ eep, sum 'read it into sum
    >DEBUG "number is ", DEC sum, CR 'I want to display sum as decimal!!!
    >
    Take a look at the DATA directive in the Stamp PBASIC Manual. Near the end
    of that section you will see an example of exactly what you are trying to do.
    A WORD-sized variable requires two READ commands to extract the DATA. One READ
    extracts the HIGHBYTE and the other extracts the LOWBYTE.

    Hope that gets you going again.

    Regards,

    Bruce Bates
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-09 14:16
    You need to include the WORD keyword on the read command:

    READ eep, WORD sum 'read it into sum



    Original Message
    From: "basicstampede" <basicstampede@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, June 09, 2003 4:42 AM
    Subject: [noparse][[/noparse]basicstamps] How to read and display Word value from EE?


    > I want to store a decimal value in EEPROM and later show it using
    > DEBUG. Since the number is "large", I need to use Word.
    > But when I run this below, I don't get 4321, but 225.
    > What is going on? I'm using PBasic 2.5.
    >
    > Does anyone know how to read a Word decimal value from EEPROM and
    > later show it as decimal using DEBUG?
    >
    > Much thanks in advance.
    >
    > '{$STAMP BS2}
    > '{$PBASIC 2.5}
    >
    > eep VAR Word 'EE pointer
    > sum VAR Word 'variable used to store data read from EE
    >
    > data1 DATA Word 4321 'EE data
    >
    > eep = data1 'point to EE address
    > READ eep, sum 'read it into sum
    > DEBUG "number is ", DEC sum, CR 'I want to display sum as decimal!!!
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-09 14:47
    Thanks! That works perfectly!

    --- In basicstamps@yahoogroups.com, "GWR at PacBell" <GWR@P...> wrote:
    > You need to include the WORD keyword on the read command:
    >
    > READ eep, WORD sum 'read it into sum
    >
    >
    >
    >
    Original Message
    > From: "basicstampede" <basicstampede@y...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Monday, June 09, 2003 4:42 AM
    > Subject: [noparse][[/noparse]basicstamps] How to read and display Word value from EE?
    >
    >
    > > I want to store a decimal value in EEPROM and later show it using
    > > DEBUG. Since the number is "large", I need to use Word.
    > > But when I run this below, I don't get 4321, but 225.
    > > What is going on? I'm using PBasic 2.5.
    > >
    > > Does anyone know how to read a Word decimal value from EEPROM and
    > > later show it as decimal using DEBUG?
    > >
    > > Much thanks in advance.
    > >
    > > '{$STAMP BS2}
    > > '{$PBASIC 2.5}
    > >
    > > eep VAR Word 'EE pointer
    > > sum VAR Word 'variable used to store data read from EE
    > >
    > > data1 DATA Word 4321 'EE data
    > >
    > > eep = data1 'point to EE address
    > > READ eep, sum 'read it into sum
    > > DEBUG "number is ", DEC sum, CR 'I want to display sum as
    decimal!!!
    > >
    > >
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    Subject and
    > Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-09 16:00
    Since the EEPROM is designed to store Bytes, WRITE and READ default to Bytes
    (just as the DATA statement does). And as you modified the DATA statement to
    store a Word, you can do the same thing with READ. Like this:

    READ eep, Word sum

    This actually causes the compiler to generate this code:

    READ eep, sum.LOWBYTE
    READ eep+1, sum.HIGHBYTE

    Obviously, using the Word modifier is easier.

    -- Jon Williams
    -- Parallax

    In a message dated 6/9/2003 6:43:42 AM Central Standard Time,
    basicstampede@y... writes:

    > I want to store a decimal value in EEPROM and later show it using
    > DEBUG. Since the number is "large", I need to use Word.
    > But when I run this below, I don't get 4321, but 225.
    > What is going on? I'm using PBasic 2.5.
    >
    > Does anyone know how to read a Word decimal value from EEPROM and
    > later show it as decimal using DEBUG?
    >
    > Much thanks in advance.
    >
    > '{$STAMP BS2}
    > '{$PBASIC 2.5}
    >
    > eep VAR Word 'EE pointer
    > sum VAR Word 'variable used to store data read from EE
    >
    > data1 DATA Word 4321 'EE data
    >
    > eep = data1 'point to EE address
    > READ eep, sum 'read it into sum
    > DEBUG "number is ", DEC sum, CR 'I want to display sum as decimal!!!



    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.