Shop OBEX P1 Docs P2 Docs Learn Events
issue with debugin, write, read, debug — Parallax Forums

issue with debugin, write, read, debug

chzchz Posts: 8
edited 2006-04-28 20:43 in BASIC Stamp
i've been trying to follow the manual for quite some time and i am still not understanding how to WRITE a variable after DEBUGIN and then READing it back with a DEBUG to follow. heres what i have followed by my input of 4304
' {$STAMP BS2}
' {$PBASIC 2.5}

counter VAR Word
counter = 0
'PAUSE 3000
valin VAR Word(3)
valout VAR Word(3)

DEBUGIN DEC4 valin
WRITE 0, Word valin
READ 0, valout(0), valout(1), valout(2)
DEBUG DEC1 valout(0), DEC1 valout(1), DEC1 valout(2)


4304861



PLEASE HELP! thanks in advance

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-28 19:43
    Hello,

    ·· Wht aren't you reading the DATA values back in to a WORD variable?· The data is actually stored as two bytes when you use a WORD variable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • chzchz Posts: 8
    edited 2006-04-28 19:52
    ahh..thank you!

    how bout if i wanted to write say 300 at location 0, but i wanted to read exactly starting from 0, 300 back instead of 0300? i want to be able to write to memory 3 characters at a time only using 3 mem spaces, but it seems to take up 4 mem spaces.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-28 19:56
    I think you're misunderstanding how they're written.· A WORD is going to be a single value from 0 through 65535.· A byte is from 0 through 255.· When you write a WORD variable it is written LOWBYTE then HIGHBYTE.· If you want to store the individual digits then you cannot use DEBUGIN with the DEC modifier because it packs the whole value into a single WORD variable if that's what you specify.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • chzchz Posts: 8
    edited 2006-04-28 20:02
    hmm...so i'd be stuck with two bytes regardless..unless i use some OR function, but i'd rather not deal with the hassle. maybe some other time.

    thanks for the help! roll.gif
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-28 20:05
    You were going to use three bytes before...You only need two to store a number up to 65535.· With a single byte you could store a number as large as 255.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • chzchz Posts: 8
    edited 2006-04-28 20:09
    oooo....sorry, ur rite. i wasnt thinking. its been a long day.
  • edited 2006-04-28 20:16
    If you are writing and reading from EEPROM, an array is not necessary.· Try this, it uses a single variable (value) to store values temporarily until they are written to/read from EEPROM.· One additional variable is (counter) is used for loop indexing.· Note also that when word values are used, the counter variable has to be incremented by 2 since the EEPROM is organized in bytes.· When storing and retrieving byte values, the index only has to be incremented by 1.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    Label DATA @10, "abcdef"
     
    counter VAR Nib
    value   VAR Word
    small   VAR value.LOWBYTE
    
     
    DEBUG "Enter three values between 0 and 255:", CR
     
    FOR counter = 0 TO 2
      DEBUGIN DEC small
      WRITE counter, small
    NEXT
     
    DEBUG "The values are:", CR
     
    FOR counter = 0 TO 2
      READ counter, small
      DEBUG DEC small, CR
    NEXT
     
    DEBUG "Enter three between 0 and 65535:", CR
     
    FOR counter = 0 TO 4 STEP 2
      DEBUGIN DEC value
      WRITE counter, Word value
    NEXT
     
    DEBUG "The values are:", CR
     
    FOR counter = 0 TO 4 STEP 2
      READ counter, Word value
      DEBUG DEC value, CR
    NEXT
     
    DEBUG "DATA values:", CR
     
    FOR counter = 0 TO 5
      READ Label + counter, small
      DEBUG small
    NEXT
    
    

    Post Edited (Andy Lindsay (Parallax)) : 4/28/2006 8:20:48 PM GMT
  • chzchz Posts: 8
    edited 2006-04-28 20:27
    awesome! that cleared up alot. thanks so much
  • edited 2006-04-28 20:43
    Excellent, glad it helped.·

    One other note.· The DATA directive was given a starting address of 10 in EEPROM.· This prevented the WRITE operations (which went up to address 5) from overwriting the "abcdef".· The DATA directive only writes values to EEPROM once, when the program is downloaded.· After that, the programmer has to make sure not to overwrite them.·

    I find it helpful to add empty DATA directives to define the portions of EEPROM that WRITE commands will have access to.· For example:

    RwVals DATA @2, (6)
    Label· DATA @8, "abcdef"

    Since RwVals now starts at address 2, all READ and WRITE commands in the FOR...NEXT loops will have to use RwVals + counter in their Address arguments (instead of just counter).· This means the FOR...NEXT loops can always start from 0.· If you need to write more values, make sure to increase the starting address of the Label DATA directive.

    (Modified code attached.)
Sign In or Register to comment.