Read/Write problems

Dracion

New Member
Ive been having further issues with my 'electronic safe'. I'm using the read/write commands so that I can store the variables in the chips memory and use them to compare the values entered using a keypad to determine if the right code has been entered. I need to do this as I'm including a feature in my program which allows the code to be changed. However, they don't seem to be working as I planned. At the beginning of the program the chip is told to:

Code:
	'This section is (should) only executed the first time the program runs.
	write b7,2
	write b8,4
	write b9,7
	write b10,10
	'Value of key +1
After this I enter the correct code using the keypad, and the chip is told to execute the following code. The values for b2-b5 are 2,4,7,10 respectively.

Code:
	read b7,b7
	read b8,b8
	read b9,b9
	read b10,b10
	if b2=b7 and b3=b8 and b4=b9 and b5=b10 then goto safeopen
I'm not sure what the problem is; either the chip isn't storing the variables or it isn't recalling them properly. Am I using the command incorrectly/the wrong command?

Many thanks, Dracion
 

hippy

Ex-Staff (retired)
"Write b7,2", "Read b7,b7" ... The first parameter for the command is the address of where to write to or read from. The 'b7' is a variable, most likely containing zero when you first start, and who knows what else later on. You really need to use hard-wired locations within the Eeprom, this should perform better ...

Code:
'This section is (should) only executed the first time the program runs.
    Write 0,2
    Write 1,4
    Write 2,7
    Write 3,10

    read 0,b7
    read 1,b8
    read 2,b9
    read 3,b10
    if b2=b7 and b3=b8 and b4=b9 and b5=b10 then goto safeopen
 

BeanieBots

Moderator
I don't think the commands read/write work in the way you expect them to.
The syntax "Write b7,2" will place the value 2 in a memory location which is determined by whatever value is held by the variable b7.

Without knowing what the value of b7 is at the start of your code, it is not possible to tell where the value of 2 will be put in your example code.

Similarly for read, "Read b7,b7" means:-
Make the value of variable b7 equal to the memory contents of the location in memory currently pointed to by the contents of b7. I'm quite sure that's not what you want to do.

Have another read of the read/write commands in the manual.
If it still doesn't make sense, ask again and I'm sure someone will explain it much better than I can.

EDIT:-
Hippy got there first, and much better explanation
 
Top