Reading / storing variables problem

davidwf

Senior Member
I am having problems reading / storing variables.....
I am using a PICAXE 18X chip and the "official" test PCB from Rev-Ed to read the value of the on board LDR ....so far so good then...

from the attached test program, the 1st time I read the variables they appear to be correct, when I read them again several have changed (notably w0 & b6) but as far as I can see they should not have changed...have attached a txt file showing this

Obviously I have missed something fundamental but cannot see what.

Thanks in advance
 

Attachments

goom

Senior Member
A quick look reveals that you may be overlapping byte and word variables. Remember that, for example, W0 is made up of b0 and b1, W4 is b6 and b7 etc. So, if you change W4, you also change b6 and b7. If you change b6 or b7, you also change W4.

Hope that this helps.
 

davidwf

Senior Member
A quick look reveals that you may be overlapping byte and word variables. Remember that, for example, W0 is made up of b0 and b1, W4 is b6 and b7 etc. So, if you change W4, you also change b6 and b7. If you change b6 or b7, you also change W4.

Hope that this helps.
bugger.....didn't realise that.....oh well back to the drawing board

thank you for the prompt reply
 

davidwf

Senior Member
A quick look reveals that you may be overlapping byte and word variables. Remember that, for example, W0 is made up of b0 and b1, W4 is b6 and b7 etc. So, if you change W4, you also change b6 and b7. If you change b6 or b7, you also change W4.

Hope that this helps.
Yep, that seems to have cured that problem...thanks again

....how many "b" variables can I have ?
 

westaust55

Moderator
PICAXE Variables

The number of variables and the relationship between word and byte variables are explained in PICAXE manual 2 page 9 under the heading Variables – General

Furthermore, for a pictorial representation and working sheet have a look at the variable map sheet I generated some time ago at (see post 10):
http://www.picaxeforum.co.uk/showthread.php?t=9525
 

davidwf

Senior Member
westaust55....

nice one !

but when I try to use b15 or w7 on my 18X it fails sytntax error...seems like I "only" have b0 to b13 or w0 to w6.

Is there a way of extending these ?

thanks
 

westaust55

Moderator
David,

Just spied an error in my variable char which relates only to the PICAXE 18X.

Have just now uploaded a version 5b to correct that.

You will find that the locations $CO (=192) to $EF (=239) are shown in the SFR area on my Varaiable map (now with a white region and note indicating they are accessible to the 18X as well).

Note that locations $50 (=80) to $7E (=126) also also available for peek and poke to store and retrieve data.
 
Last edited:

davidwf

Senior Member
Look up "peek" and "poke" commands. An extra 48 storage locations on the -18X.
aaaaaaarrrggghh....the dreaded peek 'n' poke :eek: .....I always wondered what they were for, now I will have to find out :D

Thanks for the info
 

davidwf

Senior Member
Now be patient with me please....

from posts #7 & #8 it seems that I may have to use peek & poke for additional storage.....having never come across these before I am unsure how to address the locations - i.e. does it have to be in hex or can I use decimal ?

I HAVE looked at the commands in manual 2 but still can't grasp it....but I am willing to give it a try !

A couple of SIMPLE examples would be appreciated

Thanks for your patience :)
 

westaust55

Moderator
The memory location can be addressed in either decimal or hexadecimal.
Use which ever you are comfortable with. location $C0 and location 192 are one and the same.

so to save a value at that location you just usea and say we have
b0 = 55, then these all achieve the same thing:

poke $C0, b0
poke $C0, 55
poke 192, b0
or
poke 192, 55


to get that value back we use:

peek $c0, b0
or
peek 192, b0


you can save several byte variables at once with

poke $c0, b0, b1, b2, b3 . . . .

and retrieve them with

peek 192, b0, b1, b2, b3 . . . . .
 

Pekari

Senior Member
Thanks, maybe I have a need to use this sometime.

a) How many value can I save in one time?
b) May a value be >255?
 

westaust55

Moderator
Yes you can use a value > 255 but to do that you must:
1. Add the Keyword WORD and use a word variable (eg w5, etc)

So the Poke command would become along the lines:

POKE location, byte_value1, byte_value2, WORD word_value


unsure how many values you can save at one time.
I have typically limited myself to 8 for formatting reasons.
Just tried 40 values in the simulator and that seemed to work.
 
Last edited:
Top