Shop OBEX P1 Docs P2 Docs Learn Events
EEPROM - Write 4 digit decimal number — Parallax Forums

EEPROM - Write 4 digit decimal number

danlodanlo Posts: 5
edited 2007-02-26 13:36 in BASIC Stamp
i want to write 4 digit decimal number into EEPRom, but the value of each eeprom cell can only store 0 - 255 value.
How to store 4 digit decimal number e.g 2005 into EEProm?... Would you give me some suggestions?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-26 10:16
    danlo -

    EEPROM's are generally byte oriented devices. Thus, to write anything, number or otherwise, if it takes more than one byte to contain it, you need to write the appropriate number of bytes one-at-a-time. A 4 digit number can be contained in a WORD (2 bytes) variable. Therefore you need to write two byter as shown below:

    number VAR WORD

    number = 2005

    WRITE 0, number.highbyte···· 'Check exact syntax in the PBASIC manual
    WRITE 1, number.lowbyte

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 2/26/2007 12:15:47 PM GMT
  • ZootZoot Posts: 2,227
    edited 2007-02-26 13:36
    You can also write the entire word in one command. Note however, that writing a Word writes the LOWBYTE *first*, so when writing individual bytes you might want to write lower bytes first for consistency:

    number VAR WORD
    number = 2005
    WRITE 0, Word number    'now number.LOWBYTE is at address 0, number.HIGHBYTE is at address 1
    
    ' above is same as doing this:
    WRITE 0, number.LOWBYTE   
    WRITE 1, number.HIGHBYTE
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.