Read and Write questions

pilko

Senior Member
Hi everyone,
I'm trying to understand how to use read and write to store a series of data.
I wrote this code for practice. I'm trying to store 1,2,3,4,5,6,7,8,9 and 10 in b0: 2,4,6,8 and 10 in b1: and 1,3,6, and 9 in b2. All I see in the serial window is 10,10,10
What am I doing wrong?

Thanks

pilko

Code:
main:

pause 200

let b9=b9+1

if b9>12 then aa


let b0=b0+1MAX 10
let b1=b1+2MAX 10
let b2=b2+3MAX 10

write b3,b0
write b3,b1
write b3,b2

goto main

aa:
read b3,b0
read b3,b1
read b3,b2


sertxd (#b0,#b1,#b2,cr,lf)
 

russbow

Senior Member
Pilko, doesn't this sequence

write b3,b0
write b3,b1
write b3,b2
overwrite b0 and b1 and leave b3 always containing b2

and this

read b3,b0
read b3,b1
read b3,b2
always give the same value in b0, b1 and b3

In both sections you have not incremented the b3 location.
 

pilko

Senior Member
Thanks for your help Russbow. I'm really struggling with this. How do I increment the b3 location?
Regards

pilko
 

pilko

Senior Member
hippy ---thanks for your replay---tried your suggestion still not working---I must be still doing something wrong

Code:
main:

pause 200

let b9=b9+1

if b9>12 then aa


let b0=b0+1MAX 10
let b1=b1+2MAX 10
let b2=b2+3MAX 10
let b3=b3+1MAX 10

write b3,b0
write b3,b1
write b3,b2

goto main

aa:
read b3,b0
read b3,b1
read b3,b2


sertxd (#b0,#b1,#b2,cr,lf)
 

russbow

Senior Member
No Pilko, it's the b3 that needs to be incremented.

Code:
write b3,b0
write b3,b1
write b3,b2
does not increment the pointer. Try this

Code:
write b3,b0
b3=b3+1
write b3,b1
b3=b3+1
write b3,b2
and do a similar thing with the read process

It would be tidier to use a loop, but crack this first
 

pilko

Senior Member
With this code, the serial window now shows 1000

regards

pilko

Code:
main:

pause 200

let b9=b9+1

if b9>12 then aa


let b0=b0+1MAX 10
let b1=b1+2MAX 10
let b2=b2+3MAX 10


write b3,b0
b3=b3+1
write b3,b1
b3=b3+1
write b3,b2

goto main

aa:
read b3,b0
b3=b3+1
read b3,b1
b3=b3+1
read b3,b2


sertxd (#b0,#b1,#b2,cr,lf)
 

BeanieBots

Moderator
You need to put b3 BACK to the start address before you read.

Try making use of the symbol command, it makes life so much easier.

Symbol Address=b3

address=0

write address,1
address=address+1
write address,2
address=address+1
write address,3

address=0 'point back to the start address.
read address,b0
address=address+1
read address,b1
address=address+1
read address,b2

easier to read and therefore easier to understand.
 

westaust55

Moderator
and instead of
b3 = b3 + 1​
it does not save program space but you can use
inc b3​
which gives the definite suggestion of incrementing (by 1)

See PICAXE manual 2 (v6.9) page 91
 

pilko

Senior Member
thanks folks---tried your suggestions but now just get 1,2,3 in the serial terminal.

Code:
Symbol Address=b3
main:

pause 200

let b9=b9+1

if b9>12 then aa


let b0=b0+1MAX 10
let b1=b1+2MAX 10
let b2=b2+3MAX 10

address=0

write address,1
inc address
write address,2
inc address
write address,3

goto main

aa:

address=0 'point back to the start address

read address,b0
inc address
read address,b1
inc address
read address,b2


sertxd (#b0,#b1,#b2,cr,lf)
 

westaust55

Moderator
thanks folks---tried your suggestions but now just get 1,2,3 in the serial terminal.

Code:
Symbol Address=b3
main:

pause 200

let b9=b9+1

if b9>12 then aa


let b0=b0+1MAX 10
let b1=b1+2MAX 10
let b2=b2+3MAX 10

address=0

write address,[B][COLOR="Red"]1[/COLOR][/B]
inc address
write address,[B][COLOR="Red"]2[/COLOR][/B]
inc address
write address,[B][COLOR="Red"]3[/COLOR][/B]

goto main

aa:

address=0 'point back to the start address

read address,b0
inc address
read address,b1
inc address
read address,b2


sertxd (#b0,#b1,#b2,cr,lf)
1, 2 and 3 are the values you are saving (see where I edited values to red in above quoted code) so that is correct, they are the values you will read back.
 

pilko

Senior Member
I understand what you are saying westaust but I'm trying to store 1,2,3,4,5,6,7,8,9 and 10 in b0: 2,4,6,8 and 10 in b1: and 1,3,6, and 9 in b2

Regards

pilko
 

westaust55

Moderator
think that where you have the 1, 2 and 3 that I highlighted in red you might have meant b0, b1, b2 ?


also


with the looping you are doing in the line
address=0

above the write commands, do you need to move this outside the looping code.
 
Last edited:

westaust55

Moderator
I think this is the same as what you are doing but is it what you want it to do?

Code:
Symbol Address=b3
main:

pause 200
b9 = 0 ; =0 by default when PICAXE first starts
do
	inc b9
	let b0=b0+1MAX 10
	let b1=b1+2MAX 10
	let b2=b2+3MAX 10
loop until b9>12

address=0

write address,b0
inc address
write address,b1
inc address
write address,b2


address=0 'point back to the start address

read address,b0
inc address
read address,b1
inc address
read address,b2


sertxd (#b0,#b1,#b2,cr,lf)

EDIT:
wrt the
1,3,6, and 9 in b2
will in fact go 3, 6, 9, 10, 10 , 10 . . . . 10 as b9 increments from 1 to 13 (ie b9 >12)
 

pilko

Senior Member
With this code I just show 1,2,2 in the terminal window. I guess what I am trying to do is Data log

Code:
Symbol Address=b3

address=0
main:

pause 200

let b9=b9+1

if b9>12 then aa


let b0=b0+1MAX 10
let b1=b1+2MAX 10
let b2=b2+3MAX 10



write address,b0
inc address
write address,b1
inc address
write address,b2

goto main

aa:

address=0 'point back to the start address

read address,b0
inc address
read address,b1
inc address
read address,b2


sertxd (#b0,#b1,#b2,cr,lf)
 

hippy

Ex-Staff (retired)
I'm trying to store 1,2,3,4,5,6,7,8,9 and 10 in b0: 2,4,6,8 and 10 in b1: and 1,3,6, and 9 in b2
With this code I just show 1,2,2 in the terminal window. I guess what I am trying to do is Data log
Can you explain exactly what you expect to be placed in Eeprom and where, and what you expect to see in the terminal when the program finishes ?

That's more a rhetorical question than a request for you to do so. I would suggest stepping through the code with the Simulator to see exactly what your program is doing and where it does not match your expectations.
 

pilko

Senior Member
I eventually want to log three temperatures. This code is just for practice. I was attempting to generate a series of numbers ;
bo = 1,2,3,4,5,6,7,8,9,10
b1 = 2,4,6,8,10
b2 = 3,6,9,
and log them.
I expected the terminal to show;

1,2,3,
2,4,6,
3,6,9
4,8,10
5,10,10
6,10,10
7,10,10
8,10,10
9,10,10
10,10,10

Regards

pilko
 

lbenson

Senior Member
>I'm trying to store 1,2,3,4,5,6,7,8,9 and 10 in b0: 2,4,6,8 and 10 in b1: and 1,3,6, and 9 in b2

I find this terminology confusing, since, of course, you can only store one number at a time in b0, b1, or b2.

Guessing, I'd say you are trying to store some 1-byte numbers in eeprom and read them back, and for this exercise you've chosen 19 particular numbers, those given above.

Here's one way. The assumption is that those numbers will be stored in locations 0-18 in the eeprom of a 28x1 in the order given, and then read back.

Code:
' 28eeprom
#picaxe 28x1

symbol datum = b12
symbol address = b13

address = 0
for datum = 1 to 10
  write address,datum
  inc address
next datum

for datum = 2 to 10 step 2
  write address,datum
  inc address
next datum

  write address,1
  inc address

for datum = 3 to 9 step 3
  write address,datum
  inc address
next datum

for address = 0 to 18
  read address,datum
  sertxd(#datum)
next address
 

hippy

Ex-Staff (retired)
I expected the terminal to show
Thanks, that makes things a lot clearer. Your code in post #15 is almost right, except for two things -

1) You are actually writing 12 sets of 3 bytes of data to Eeprom ( b9 runs from 1 to 12 )

2) There's a missing increment after writing the 3 bytes of data so you aren't moving address in increments of 3.

3) You only output one set of the 3 bytes of data when you display on the terminal. You will need a loop to retrieve the data just as you did for storing the data initially.

Simulation will show all of these things happening.
 
Last edited:

lbenson

Senior Member
Like this?

Code:
main:

pause 200

let b9=b9+1

if b9>12 then aa


let b0=b0+1MAX 10
let b1=b1+2MAX 10
let b2=b2+3MAX 10

write b3,b0
inc b3
write b3,b1
inc b3
write b3,b2
inc b3

goto main

aa:
b3 = 0
dec b9
for b12 = 1 to b9
  read b3,b0
  inc b3
  read b3,b1
  inc b3
  read b3,b2
  inc b3

  sertxd (#b0,#b1,#b2,cr,lf)
next b12
 
Last edited:

pilko

Senior Member
Thanks everyone for your help.
Couldn't respond right away (had to clear a foot of snow from driveway)
Ibenson, your code works, (now trying to figure it out)
So much to learn, but it's great fun and given me a new lease on life.

Regards

pilko
 

lbenson

Senior Member
>code works, (now trying to figure it out)

You can single-step it in the simulator. You loop 12 times writing to 3 eeprom locations in your initial loop (for a total of 36 bytes written), so you need to loop 12 times reading 3 locations when you read the data back.
 
Top