write and read from eeprom problem

Puuhaaja

Senior Member
Hi again!

I have planned a program where I need to set different numbers to lcd screen like: 32,45

Each number can get value from 0 to 9.

number 3 is stored to b1, 2 to b2, 4 to b4 and 5 to b4

At end of the program I have a code:

Code:
write b6, b1
write b7, b2
write b8, b3
write b9, b4
and at teh beginning:
Code:
let b5 = 198
read b6, b1
read b7, b2
read b8, b3
read b9, b4 

low b.0
pause 1000
serout b.0, n2400, (254, 1)
pause 600

main:
serout b.0, n2400, ( 254, 128 )
program continues....
The big problem is that
when i have in the end:

write b6, b1
write b7, b2
write b8, b3
write b9, b4

that means that values b1, b2, b3 get same value than b4. When I change line orders the other b1-b4 places get their values from the last line in the code. I suppose you understand the point.
So...how could I solve this problem or is there other methods to store data to non-volatile memory?
 

westaust55

Moderator
Are you giving the byte variable b6, b7, b8 and b9 values? If not they might all be 0 so all values in b1, b2, b3 and b4 are all written to the same EEPROM location.

Try:
Code:
[code]
b0 = 0 ;or some other EEPROM starting location
read b6, b1
inc b6
read b6, b2
inc b6
read b6, b3
inc b6
read b6, b4
and
Code:
b0 = 0 ;use same value for EEPROM address as above
write b6, b1
inc b6
write b6, b2
inc b6
write b6, b3
inc b6
write b6, b4
 

BeanieBots

Moderator
The line "write b6, b1" means put the value held in b1 into the location pointed to by the value of b6.
Is that what you really mean to do?
As pointed out by westy, are you giving values to the variables you are using as EEPROM pointers?
 

Puuhaaja

Senior Member
I'm so lost with those read and write commands. I try to explain.

In lcd I have have number 00,00
with ir remote controller I change value to 10,05
Now number 1 is stored in b1 and number 5 is stored in b4 etc..

edit:
Then I have to put values b1, b2, b3 and b4 to wwprom memory area.
when I switch power off and turn it on again there should be number 10,05 in lcd screen.
When come back to home I will try your advices.
 
Last edited:

Puuhaaja

Senior Member
I didn't get it working with those commands.

The line "write b6, b1" means put the value held in b1 into the location pointed to by the value of b6.
Is that what you really mean to do?
If I have a number 54,31

b1 holds number 5. b1 can get values from 0 to 9

After that b1 is saved to eeprom with write b6,b1 command.
Where is the problem what i'm doing?
 

westaust55

Moderator
Can you please post your entire program listing so that we can verify exactly what you are doing.

You can try using the SERTXD command to send the values via the AXE027 cable from the PICAXE to your PC to verify the values just before you write and just after you read the values.
The values can be seen in the Programming Editor terminal window (stated by pressing the [F8] key ). CHeck the bause rate matches your PICAXE speed ==> 4 MHz = 4800 bps, 8 MHz = 9600 bps.

Add a command such as:
SERTXD (#b1, " ", #b2, " ", #b3, " ", #b4, CR, LF)
which will allow you to verify the values in the four variables on your PC screen as the PICAXE program runs.

If I have a number 54,31
youa re holding each digit in a separate byte variable. Are these really discrete numbers or are there really two values "54" and "31" in which case you can/may be able to store in just two byte variables. Is the comma (,) your decimal point or a value separator.
If it is a comma then you could hold the entire number in a word value * 100 so 54,31 (or 54.31) is stores in a word variable as 5431 for program operating purposes and saved as the high and low byte of the word varial.
 

hippy

Technical Support
Staff member
b1 holds number 5. b1 can get values from 0 to 9

After that b1 is saved to eeprom with write b6,b1 command.
Where is the problem what i'm doing?
See post #3; "The line "write b6, b1" means put the value held in b1 into the location pointed to by the value of b6. Is that what you really mean to do?"

After "write b6,b1", the value of b1 will be saved into Eeprom, but where to ?

The question you need to ask yourself is; Why are you using 'b6' ?
 

Puuhaaja

Senior Member
Here's the whole code.

Main idea of code: I have lcd screen and at first there's a number 00,00. With ir remote controller I change number to 12,34. After powering off Picaxe will remember that number and next time when I turn picaxe on there's a number 12,34 on lcd screen. The code written below is not working. Instead of 12,34 it's showing 44,44. I don't know how to modify this code so advices are wellcome.


' b0 = ir remote controller
' b1 = tens metres
' b2 = metres
' b3 = 1/10 metres
' b4 = 1/100 metres
' b5 = place for blinking cursor

let b5 = 198 ' blinking cursor starting point
read b6, b1
read b7, b2
read b8, b3
read b9, b4

low b.0
pause 1000
serout b.0, n2400, (254, 1)
pause 600

main:
serout b.0, n2400, ( 254, 128 )
serout b.0, n2400, ( "Test screen " )
serout b.0, n2400 , (254, 192)
serout b.0, n2400, ( "metre")
serout b.0, n2400, (254, 198) 'tens metres
serout b.0, n2400, (#b1)
serout b.0, n2400, (254, 199) 'metres
serout b.0, n2400, (#b2)
serout b.0, n2400, (254, 200) ' comma/decimal point
serout b.0, n2400, (",")
serout b.0, n2400, (254, 201) ' 1/10 metres
serout b.0, n2400, (#b3)
serout b.0, n2400, (254, 202) '1/100 metres
serout b.0, n2400, (#b4)

serout b.0, n2400, (254, b5)
serout b.0, n2400, (254, 13)
pause 200

let b0 = 0
irin [400,main], C.2, b0
if b0 = 18 then inc b5 ' move blinking cursor right
elseif b0 = 19 then dec b5 'Move blinking cursor left
end if

if b5 = 200 and b0 = 18 then let b5 = 201 'Jump right over the decimal point
elseif b5 = 200 and b0 = 19 then let b5 = 199 ' Jump left over the decimal point
end if

if b5 = 203 then let b5 = 202 ' Don't allow blinking cursor to move to much right
else if b5 = 197 then let b5 = 198
end if

'chancing tens metres
if b5 = 198 and b0 = 16 then inc b1 ' inc tens metres
elseif b5 = 198 and b0 = 17 then dec b1 'dec tens metres
end if
if b1 = 10 then let b1 = 9 ' don't allow value be bigger than 9
end if
if b1 = 255 then let b1 = 0 ' don't allow value be smaller than 0
end if

'chancing metres
if b5 = 199 and b0 = 16 then inc b2 ' inc metres
elseif b5 = 199 and b0 = 17 then dec b2 'dec metres
end if
if b2 = 10 then let b2 = 9 ' don't allow value be bigger than 9
end if
if b2 = 255 then let b2 = 0 ' don't allow value be smaller than 0
end if

'chancing 1/10 metres
if b5 = 201 and b0 = 16 then inc b3 ' inc 1/10 metres
elseif b5 = 201 and b0 = 17 then dec b3 'dec 1/10 metres
end if
if b3 = 10 then let b3 = 9 ' don't allow value be bigger than 9
end if
if b3 = 255 then let b3 = 0 ' don't allow value be smaller than 0
end if

'chancing 1/10 metres
if b5 = 202 and b0 = 16 then inc b4 ' inc 1/100 metres
elseif b5 = 202 and b0 = 17 then dec b4 'dec 1/10 metres
end if
if b4 = 10 then let b4 = 9 ' don't allow value be bigger than 9
end if
if b4 = 255 then let b4 = 0 ' don't allow value be smaller than 0
end if
pause 100

write b6, b1
write b7, b2
write b8, b3
write b9, b4

debug

goto main
 

MartinM57

Moderator
Try...

let b5 = 198 ' blinking cursor starting point
read 0, b1
read 1, b2
read 2, b3
read 3, b4

...
write 0, b1
write 1, b2
write 2, b3
write 3, b4

You must read from, and write to, the same (and different!) locations.

In your code b6,b7,b8 and b9 are never used so take the value 0 - so you are always reading from and writing to EEPROM location 0 - hence all the 4's - the last value read and written
 

rossko57

Senior Member
read b6, b1
Remembering that 'b6' would contain the address that you're going to look at in the EEPROM;
You haven't put any value in b6, so you could read data from anywhere - probably EEPROM address 0 though.
read b7, b2
You haven't put any value in b7, so you could read data from anywhere - probably EEPROM address 0 though.
... and so on
 

Puuhaaja

Senior Member
AMAZING!!!

Mister Martin57 I'm so thankful for your piece of code. I got it working. I also want to thank you everybody who have enlightemented me in this thread. Next time I will try to describe my problem better so it's easier for us.
 

westaust55

Moderator
read b6, b1
Remembering that 'b6' would contain the address that you're going to look at in the EEPROM;
You haven't put any value in b6, so you could read data from anywhere - probably EEPROM address 0 though.
read b7, b2
You haven't put any value in b7, so you could read data from anywhere - probably EEPROM address 0 though.
... and so on
Exactly what was being mentioned back at post 2.
 

westaust55

Moderator
AMAZING!!!

Mister Martin57 I'm so thankful for your piece of code. I got it working. I also want to thank you everybody who have enlightemented me in this thread. Next time I will try to describe my problem better so it's easier for us.
Great to read that the problem is now resolved.
Certainly providing the entire code (unless it is some several thousands of lines long) can help to resolve problems more expediently and with certainly.
 

Puuhaaja

Senior Member
Great to read that the problem is now resolved.
Great thanks for you Westaust55 that you have answered me so many times in different threads. Shareing (knowledge) is careing.


read 0, b1
read 1, b2
read 2, b3
read 3, b4
.
.
read 27, b27
How many eeprom memory places I can use in 18m2+ chip and is there any kind of rules where to store/save those lovely little numbers. I'm asking this because the long code I had posted earlier was only one part of program which I'm designing. I don't want that my b0-bx and 0-x places lap each others.
 
Top