Shop OBEX P1 Docs P2 Docs Learn Events
eeprom organization..? — Parallax Forums

eeprom organization..?

ichoelichoel Posts: 17
edited 2009-02-25 02:47 in Robotics
Hi guys, i'm writing a program that read and write values based on present situation. It takes data from sensors
and store it to eeprom, move around for awhile then retrieves the data back. x and y are coordinate
that mark present room. Then north,east,south,west are variables that contain data from sensors.
Here's the code:

room1 DATA @20,(3)
room2 DATA @24,(3)
room3 DATA @28,(3)
room4 DATA @32,(3)
room5 DATA @36,(3)
room6 DATA @40,(3)
room7 DATA @44,(3)
room8 DATA @48,(3)
room9 DATA @52,(3)

DO
GOSUB write_data
GOSUB take_a_walk
GOSUB read_data
..
..
LOOP

write_data:
IF (x=0 AND y=0) THEN
WRITE 20,north
WRITE 21,east
WRITE 22,south
WRITE 23,west
ELSEIF (x=0 AND y=1) THEN
WRITE 24,north
WRITE 25,east
WRITE 26,south
WRITE 27,west
ELSEIF (x=0 AND y=2) THEN
WRITE 28,north
WRITE 29,east
WRITE 30,west
WRITE 31,bar
ELSEIF (x=1 AND y=0) THEN
WRITE 32,north
WRITE 33,east
WRITE 34,south
WRITE 35,west
ELSEIF (x=1 AND y=1) THEN
WRITE 36,north
WRITE 37,east
WRITE 38,south
WRITE 39,west
ELSEIF (x=1 AND y=2) THEN
WRITE 40,north
WRITE 41,east
WRITE 42,south
WRITE 43,west
ELSEIF (x=2 AND y=0) THEN
WRITE 44,north
WRITE 45,east
WRITE 46,south
WRITE 47,west
ELSEIF (x=2 AND y=1) THEN
WRITE 48,north
WRITE 49,east
WRITE 50,south
WRITE 51,west
ELSEIF (x=2 AND y=2) THEN
WRITE 52,north
WRITE 53,east
WRITE 54,south
WRITE 55,west
ENDIF
RETURN
read_data:
IF (x=0 AND y =0) THEN
READ 20,north
READ 21,east
READ 22,south
READ 23,west
ELSEIF (x=0 AND y=1) THEN
READ 24,north
READ 25,east
READ 26,south
READ 27,west
ELSEIF (x=0 AND y=2) THEN
READ 28,north
READ 29,east
READ 30,west
READ 31,bar
ELSEIF (x=1 AND y=0) THEN
READ 32,north
READ 33,east
READ 34,south
READ 35,west
ELSEIF (x=1 AND y=1) THEN
READ 36,north
READ 37,east
READ 38,south
READ 39,west
ELSEIF (x=1 AND y=2) THEN
READ 40,north
READ 41,east
READ 42,south
READ 43,west
ELSEIF (x=2 AND y=0) THEN
READ 44,north
READ 45,east
READ 46,south
READ 47,west
ELSEIF (x=2 AND y=1) THEN
READ 48,north
READ 49,east
READ 50,south
READ 51,west
ELSEIF (x=2 AND y=2) THEN
READ 52,north
READ 53,east
READ 54,south
READ 55,west
ENDIF
RETURN
..
..

I'd like to minimize this program by using looping command, but i dont know how. Any recommendation?
or better idea..?? confused.gif

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-02-12 08:29
    You can minimize this by using a function. I provided the write, and you can do something similar for read.

    temp = (((x*3) + y)*4)+20
    WRITE temp, north, east, south, west
    
    
  • ichoelichoel Posts: 17
    edited 2009-02-17 00:53
    Thanks SLRM..your function helps me alot!
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-02-25 02:47
    Note you only get 1 million "WRITE"s to a location before it wears out and goes to zero.
    So, be careful how fast your program loops.
Sign In or Register to comment.