Writing multiple variables to consecutive EEPROM slots?

Blazemaguire

Senior Member
Hi,

I'm doing a small RFID project using the 125mhz serial RFID readers of ebay. Got the reader working fine and it spits out 10 numbers which I'm storing in ten variables (B0,b1,b2,b3,b4,b5,b6,b7,b8,b9) - for simplicity, I'm not showing that part of the code as it works fine

How can I store all of these into consecutive EEPROM locations (i.e, EEPROM, b0,b1,b2,b3,b4,b5,b6,b7,b8,b9) and then, when the next scan occurs, store the next 10 variables in b0 through b9 into the next 10 eeprom slots (b10,b11,b12,b13,b14,b16,b16,b17,b18)?

I've tried this:

Code:
'This code assumes the ten numbers have already been read into the ten variables b0 through to b9

symbol start_pointer=b10
symbol finish_pointer=b11
symbol eeprom_location=b12

start_pointer=0 'start at memory location 0
finish_pointer=9 'end 10 places later so

Scan_Keyfobs:   

for eeprom_location = start_pointer to finish_pointer  'for memory location 'start' to 'finish' i.e, 0 to 9, then 10 to 19, then 20 to 29 etc
	
write eeprom_location,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9

next eeprom_location

start_pointer=start_pointer+10 'adds ten to the position counter start
finish_pointer=finish_pointer+10 'adds ten to the position counter end for the for loop

goto scan_keyfobs
This just seems to overwrite each EEPROM location with all ten variables, resulting in only the final variable actually being stored in each EEPROM slotafter all is said and done.


I can't seem to figure out how to phrase this code correctly (I'm still learning!)

At the moment I'm have to do the below to store and read the EEPROM... but this only works for the first 10 digit code recorded, and I can't wrap my head around how to amend this so the next fob I scan goes into locations, 10 through 19. Also, it seems a very clunky way of doing it.

Code:
write b0,b0
write b1,b1
write b2,b2
write b3,b3
write b4,b4
write b5,b5
write b6,b6
write b7,b7
write b8,b8
write b9,b9
Any suggestions or pointers? thanks!
 
Last edited:

Buzby

Senior Member
You don't need the for/next for each byte, as the 'write eeprom_location,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9' writes 10 bytes.

try :

do

code to read the fob into b0-b9

write eeprom_location,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9

eeprom_location = eeprom_location + 10

loop
 

AllyCat

Senior Member
Hi,

That's a classic application for an "indirection operator" (byte pointer):

Code:
bptr = 10         ; Points to b10
write eeprom_location,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
And with an M2 (except 08M2) you can do that for up to 50 sets of locations (i.e. up to bptr = 500).

Cheers, Alan.
 
Top