PDA

View Full Version : Simple External EEPROM Table Example?



modifyit
- 25th October 2006, 18:27
Can someone give me a quick external eeprom lookup table example. I know I am missing something stupid. I'm not worried about the exact code, more the thought process.

Basically what I need to do is put the following data into eeprom

(1) 00000001,00000000,00000000,00000000
(2) 00001010,00000000,00000000,00000000
(3) 00001010,00000000,00000000,00000000
(4) 00101010,00000000,00000000,00000000
(5) 10101010,00000000,00000000,00000000
(6) 10101010,00000000,00000000,00000000
(7) 10101010,00000010,00000000,00000000
(8) 10101010,00000010,00000000,00000000
(9) 10101010,00001010,00000000,00000000
(10) 10101010,00101010,00000000,00000000

After the data is in EEPROM my program will have a variable that will store a value between (1) and (10). Based on that variable I need to go to the EEPROM and return with 4 byte sized variables.

I am having trouble understanding how to format this data in eeprom effiecently so that I can get the 4 byte size variables out in a small amount of time.

Thanks for any thoughts, hopefully I have not confused everyone. :)

sayzer
- 25th October 2006, 20:18
Hi modifyit,


You will have 20 WORD size variables instead of 10.
The code will look like below. I did not use decimal numbers to make it more understandable and stored Binary numbers in EEPROM.




'LowByte, HighByte, LowByte, HighByte
EEPROM 1, [%00000001,%00000000,%00000000,%00000000]
EEPROM 5, [%00001010,%00000000,%00000000,%00000000]
EEPROM 9, [%00001010,%00000000,%00000000,%00000000]
EEPROM 13,[%00101010,%00000000,%00000000,%00000000]
EEPROM 17,[%10101010,%00000000,%00000000,%00000000]
EEPROM 21,[%10101010,%00000000,%00000000,%00000000]
EEPROM 25,[%10101010,%00000010,%00000000,%00000000]
EEPROM 29,[%10101010,%00000010,%00000000,%00000000]
EEPROM 33,[%10101010,%00001010,%00000000,%00000000]
EEPROM 37,[%10101010,%00101010,%00000000,%00000000]

LOCATOR VAR BYTE
Holder VAR WORD[21]


START:

FOR LOCATOR = 1 to 37 STEP 4

READ LOCATOR, Holder.lowbyte[LOCATOR] 'EEPROM Location 1 \
READ LOCATOR+1, Holder.highbyte[LOCATOR] 'EEPROM Location 2 /
' We read First two bytes here.

READ LOCATOR+2, Holder.lowbyte[LOCATOR+1] 'EEPROM Location 3 \
READ LOCATOR+3, Holder.highbyte[LOCATOR+1] 'EEPROM Location 4 /
' Read Second two bytes.

NEXT LOCATOR

' Print the numbers on LCD and see what is going on.

GOTO START

END


---------------------------------------
Pls check these posts.
first this http://www.picbasic.co.uk/forum/showthread.php?t=544
then
this http://www.picbasic.co.uk/forum/showthread.php?t=42.


Edit: This code is not a direct answer to your question but if you understand the way it works, then you can have a variable in your program as you said and based on its value you can do the following.

Say your variable is also named as Locator. Then you just use the same concept inside the FOR loop above and get your data from EEPROM, but remember you will have "4-bytes" from EEPROM into two WORD size variable in your program.