Shop OBEX P1 Docs P2 Docs Learn Events
Reading strings from the DATA Function — Parallax Forums

Reading strings from the DATA Function

kingbpkingbp Posts: 22
edited 2012-04-17 17:17 in BASIC Stamp
Hello I'm working on a code for the boe-bot where I'm using the DATA function to write to the EEPROM. Lets say I have a piece of code where I have DATA "FAST", how can I read this into the EEPROM, I tried using the read function like so READ "FAST" But I get an error that says Expected a variable is their an alternate way to Read "FAST" from DATA.e Im using the bs2 micro controller.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-17 08:53
    When you have a DATA statement like DATA "FAST", this causes the bytes "F", "A", "S", "T" to be written to the EEPROM when the program is downloaded to the Stamp. The READ statement will read these characters, one at a time into a variable. The first DATA statement starts putting the data into location zero and up and subsequent DATA statements use successively higher EEPROM locations. If your program has a byte variable called C, then

    READ 0,C ' puts "F" into C
    READ 1,C ' puts "A" into C
    READ 2,C ' puts "S" into C
    READ 3,C ' puts "T" into C

    Frequently you'll have some special byte value that marks the end of the string you're storing. Commonly, this is a zero byte value. Let's say you want to use DEBUG to display a string starting at location 10. You might have

    p = 10 ' initialize the pointer
    loop:
    read p, temp ' read the byte
    p = p + 1 ' increment the pointer
    if temp = 0 then goto exit ' check for end of string
    debug temp ' display the character
    goto loop
    exit:
  • davejamesdavejames Posts: 4,047
    edited 2012-04-17 08:53
    kingbp,

    Study up on the READ command in the reference manual. There you'll see that the format of the command is:

    READ Location, Variable

    ...where Location is the memory address of the data that you're after, and Variable is where the data will be held.

    The error you received was because the command format was not syntactically correct.

    Regards,

    DJ

    ***Darn! Mr. Green beat me to it, again!
  • kingbpkingbp Posts: 22
    edited 2012-04-17 15:37
    What if C is a nib would the read command still work as you posted above?
  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-17 17:17
    If C were a nib, this would work as long as you only needed the least significant 4 bits of the value from the EEPROM. The READ statement fetches the whole byte value from EEPROM and only would store 4 bits in the variable ignoring the rest.
Sign In or Register to comment.