BS2 - Reading and writing to EPROMM - Im confused
Hi everyone, id just like to ask how to read and write to the BS2's EPROMM, all the tutorials I have seen, seem to be really conpilcated!
Its for my digital dash project. I wish·to store 4·variables in EPROMM, which are all 16 bit word variables:
1)···· CIRC
2)·····RPM_LIMIT
3)·····RPM_LAUNCH
4)···· FAN_ON
At program startup these values must be recalled for use in the program and if the user wishes to change them in the setup they can. Any ideas? Im confused!
Its for my digital dash project. I wish·to store 4·variables in EPROMM, which are all 16 bit word variables:
1)···· CIRC
2)·····RPM_LIMIT
3)·····RPM_LAUNCH
4)···· FAN_ON
At program startup these values must be recalled for use in the program and if the user wishes to change them in the setup they can. Any ideas? Im confused!
Comments
For similar needs, the BasicStamp 2 uses the DATA command.
Variables must be declared as to Byte or Word length so that proper RAM locations are available. I suspect you are getting your four items confused with variables located in RAM.
The CONSTANTS declaration is what will store a value in EEPROM to be called by name from within the program. I have a bit of trouble determinining if the BasicStamp 2 with store a 16 bit constant or not. And 8 bit constant would be limited to 256 while a 16 bit constant would go over 65,000.
You may be able to store a High and Low segment of each constant to be combined after being sequentially read.
Anyone else out there?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
·· You will need to use the READ and WRITE commands to write data to the EEPROM on the BS2.· Be careful of how often these values are updated since EEPROM has a finite write lifetime and using them as variables could easily wear them out.· If you're just loading them into existing variables at startup you should be fine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
So, if by "engine changes and wheel changes", you mean when you REPLACE the engine and REPLACE the wheels, and you only do that a few times a day, no problem. If by 'engine changes' you mean you rev-up the RPM, then you'll probably have a problem.
I understand your approach and I don't have much experience with this.
I look at the PBasic Manual and read that 'all math is done in 16-bit width'.
Does that mean that any CONSTANTS can be a 16-bit number too? [noparse][[/noparse]I guess I should just test it out myself.]
If so, that is a lot easier than creating DATA space, WRITING to the DATA for a one-time input, then declaring VARIABLE word space to transfer into, and READing the data into the VARIABLE, and finally using it.
Whew!!!. As you can see, just declaring a CONSTANT would be much easier, more user friendly, and probably take up less space overall.
Can it be done?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
·· Two cases where a CONstant wouldn't work.· In his case it won't because the value needs to be changed and stored for later retrieval.· You cannot do that with a CONstant, since it cannot change.· Also, there are some other times when CONstants won't work will a DATA statement will.· Take storing string data for example.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Are there 16 bit conditions where it WILL work?
I think he is calling his input Variables in error. They appear to me to really be Constants within the program and from what I see are not being changed within the program. He is just using them to set limits and intialize the program.
Of course, I have been wrong before.........
That still leaves me unsure if Constants can handle 16 bits or only 8bits. It really is hard to infer that from the PBasic manual.
BTW, I do understand that Strings are usually much longer than Work length, so these wouldn't work.
Also, tables of DATA are only useful if you have precise knowledge of where exactly everything is. Then you can choose the 3rd or 40th item at will. Neither case seems to apply.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Post Edited (Kramer) : 3/14/2006 4:24:07 PM GMT
·· I didn't look at the code so you could be right there.· I was just addressing the use of CONstants over DATA.· Unfortunately I have to step out so I may have to glance at it later today.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
This is no problem; you simply create DATA statements to hold the values and use READ to grab them, WRITE to modify them.· Start by defining space (you can also use this to set default program start values):
Circ········ ·DATA·· ·Word 0
RPM_Limit··· ·DATA··· Word 0
RPM_Launch··· DATA··· Word 0
Fan_On······· DATA··· Word 0
Note that you must use the Word modifier to reserve two bytes for each value.· You would do this to retrieve a value:
· READ·Circ, Word circLevel
Two things: Again you must use the Word modifier, and your variable name must be unique (you can't use the same name as the DATA label).· To put a value back, it's just as simple:
· WRITE Fan_On, Word fanStatus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I will try programing some 16bit Constants for my own satisfaction.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
MyCon CON 2000
MyVar VAR WORD
MyVar = 1
while MyVar < MyCon
' Do stuff
wend ' or whatever...
Now, where 'MyCon' is in your source code, the compiler plugs in the value 2000. Thus declaring MyCon takes no variable space -- which is very nice in the tight space in a BS2.