Shop OBEX P1 Docs P2 Docs Learn Events
Looking for eeprom database/table examples — Parallax Forums

Looking for eeprom database/table examples

cdubcdub Posts: 26
edited 2006-08-07 03:13 in BASIC Stamp
I'm looking for any examples of using external eeprom to store lookup data used with a BS2.
I'm looking for something along the lines of the way the data command allows a variable name to represent an eeprom address location.· I'd like to be able to search for a value in eeprom (like an index), then return a related value( like a second field of a data row).


Thanks,
Cdub

Post Edited (cdub) : 8/7/2006 2:11:20 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-08-07 02:46
    table data 1,55, 2,66, 5, 77, 7, 99, 0
    lookFor:
        i = table
    lookAt:
        read i,word firstItem, word secondItem
        i = i + 4
        if firstItem = 0 then noMatch
        if firstItem <> goalItem then lookAt
        return
    
    


    This is a simple code fragment that is called as a GOSUB lookFor. It uses a table in program EEPROM of pairs of words.
    The first of a pair is an index that's matched against goalItem. If a match is found, secondItem is set to the second of
    the matching pair. If firstItem is zero, no match was found because the terminating zero was found.
    If you want to use an external EEPROM, you could use the I2C command set to access the EEPROM and simply substitute
    an I2CIN statement for the READ statement like (with i initially zero and all variables here are words):
        I2CIN pin,$A0,i SHR 8\i,[noparse][[/noparse]firstItem.BYTE0,firstItem.BYTE1,secondItem.BYTE0,secondItem.BYTE1]
    
    
  • cdubcdub Posts: 26
    edited 2006-08-07 03:00
    I'm only able to use the BS2 not "p", so I don't have that command set available.
    I'm currently using sample code found at the 24LC128 product page for the BS2, but it only shows how to set a value then immediately read it back.· It is useful as a start but not robust enough for my application.
    this is the link: http://www.parallax.com/dl/docs/prod/oem/24LC128-v2.0.pdf.

    I'm basically trying to use external eeprom in the taos color sensor example(by jon williams), but with many more colors in a lookup table.
    Here is the link:
    http://downloads.nutsvolts.com/Color_Scan.BS2


    Post Edited (cdub) : 8/7/2006 3:05:20 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-07 03:09
    cdub -

    You can also use external EEPROM's with an SPI/Microwire interface, and use the SHIFTIN and SHIFTOUT commands.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Mike GreenMike Green Posts: 23,101
    edited 2006-08-07 03:13
    The same idea works with the BS2. It's just not as straightforward. Package up the EEPROM read a byte routine as a subroutine with the EEPROM address in eeprom_add which you treat like "i" in my example. You have to increment eeprom_add for each byte that you read and copy the value in temp to where you want it (like firstItem.byte0, etc.) like:
      eeprom_add = 0
    lookAt:
      call readAByte
      firstItem.byte0 = temp
      eeprom_add = eeprom_add
      call readAByte
      firstItem.byte1 = temp
      eeprom_add = eeprom_add
     ... and so on for secondItem
    
    


    You probably would have one program to set up the table in the EEPROM and another program
    to actually use it for your color sensor table.
Sign In or Register to comment.