Shop OBEX P1 Docs P2 Docs Learn Events
Problem while Writing into EEPROM of Boe-Bot — Parallax Forums

Problem while Writing into EEPROM of Boe-Bot

heavy-freelancerheavy-freelancer Posts: 23
edited 2011-01-13 11:31 in Robotics
Hey,

I have to remember a value of some variables when running my program.

So I've looked into the BASIC Stamp Manual v2.2, and found some instructions that may help.

I've created 2 programs. the first to write to EEPROM, and the other to read from it, like shown here :

1st program:
DATA @10, 55

2nd program:
myCounter VAR Word
READ 11, myCounter
DEBUG DEC myCounter

This is working great, but I want to do this in the 1st program :

Temp VAR Word
Temp = 44
DATA @10, Temp

The compiler is giving me an ERROR here.

Because I'm using many instruction in my program, I need to store the value of the variable in the adresse @10 instead.

Do you have any ideas.

Thanks

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-01-11 10:23
    I believe you're looking for the WRITE instruction.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-11 10:40
    Also, do you mean "READ 11, myCounter" or do you mean "READ 10, myCounter"? The first parameter to the READ (and WRITE) statement is the address in EEPROM to use.
  • heavy-freelancerheavy-freelancer Posts: 23
    edited 2011-01-11 10:57
    Mike Green wrote: »
    Also, do you mean "READ 11, myCounter" or do you mean "READ 10, myCounter"? The first parameter to the READ (and WRITE) statement is the address in EEPROM to use.

    DATA & WRITE are the same Mike G ?

    Sorry, I mean 11:

    1st program:
    Temp VAR Word
    Temp = 44
    DATA @11, Temp 'How can I send to value of Temp here ?

    2nd program:
    myCounter VAR Word
    READ 11, myCounter
    DEBUG DEC myCounter
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-11 11:05
    DATA and WRITE are different. DATA is a declaration that tells the Stamp Editor to download the specified data to specific locations in the EEPROM while it's downloading the compiled program to other parts of the EEPROM. WRITE is a statement (like READ) that writes a byte value to a specified location in EEPROM as the statement is being executed. Similarly, READ reads a byte value from a specified location in EEPROM into a variable.

    Look at the description of the DATA, READ, and WRITE statements in the Stamp Manual or the Stamp Editor's help files.
  • heavy-freelancerheavy-freelancer Posts: 23
    edited 2011-01-11 11:12
    Mike Green wrote: »
    DATA and WRITE are different. DATA is a declaration that tells the Stamp Editor to download the specified data to specific locations in the EEPROM while it's downloading the compiled program to other parts of the EEPROM. WRITE is a statement (like READ) that writes a byte value to a specified location in EEPROM as the statement is being executed. Similarly, READ reads a byte value from a specified location in EEPROM into a variable.

    Look at the description of the DATA, READ, and WRITE statements in the Stamp Manual or the Stamp Editor's help files.

    Ok, I get it now.

    I don't have the robot with me right now to test, but how can write the value of Temp in the adresse @10, Is this code going to work ?

    1st program:
    Temp VAR Word
    Temp = 44
    WRITE @11, Temp

    2nd program:
    myCounter VAR Word
    READ 11, myCounter
    DEBUG DEC myCounter
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-11 11:15
    The WRITE statement does not use the "@" operator. Only the DATA statement uses it (to tell the difference between an address and a value to go in the EEPROM). Look at the examples in the documentation.
  • heavy-freelancerheavy-freelancer Posts: 23
    edited 2011-01-11 12:15
    Mike Green wrote: »
    The WRITE statement does not use the "@" operator. Only the DATA statement uses it (to tell the difference between an address and a value to go in the EEPROM). Look at the examples in the documentation.

    I don't understand really what this sentence mean : The WRITE command normally only stores byte-sized values into EEPROM.

    I'm using PBasic 2.5 with BS2.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-11 12:26
    A byte is an 8-bit unit of storage that can hold a value between 0 and 255. The EEPROM is designed to hold bytes. Each separate address holds one byte. The WRITE statement (and the READ and DATA statements) naturally deals in byte values. There is a shorthand notation in Parallax Basic that allows the use of word (16-bit) values in many statements like READ / WRITE / DATA. The Stamp Editor automatically treats a 16-bit value prefixed by WORD as two separate byte values for these statements and others where WORD is allowed. The least significant byte is stored first, followed by the most significant byte. See the Stamp Manual for examples.
  • heavy-freelancerheavy-freelancer Posts: 23
    edited 2011-01-11 13:11
    Mike Green wrote: »
    A byte is an 8-bit unit of storage that can hold a value between 0 and 255. The EEPROM is designed to hold bytes. Each separate address holds one byte. The WRITE statement (and the READ and DATA statements) naturally deals in byte values. There is a shorthand notation in Parallax Basic that allows the use of word (16-bit) values in many statements like READ / WRITE / DATA. The Stamp Editor automatically treats a 16-bit value prefixed by WORD as two separate byte values for these statements and others where WORD is allowed. The least significant byte is stored first, followed by the most significant byte. See the Stamp Manual for examples.

    I understand almost everything about the WRITE and READ commands.

    For example :

    value VAR Word

    WRITE 1, Word 2000

    READ 1, Word value

    DEBUG DEC value

    But I still can't know how to return the value of another variable to the WRITE command. Like :

    myValueVAR Word
    myValue = 2000
    WRITE 1, Word 2000 'How can I change 2000 by something to return the value of myValue
  • ZootZoot Posts: 2,227
    edited 2011-01-13 08:13
    buff VAR Word
    myValue VAR Word 
    buff = 0
    myValue = 2000
    WRITE 1, Word myValue
    
    READ 1, Word buff
    DEBUG DEC5 buff
    
  • heavy-freelancerheavy-freelancer Posts: 23
    edited 2011-01-13 11:31
    Thanks Zoot.
Sign In or Register to comment.