Write a variable into EEPROM
Tcpip_v6
Posts: 15
I’m trying the write a variable into the EEPROM of a BS2.
This is what I try to do:
WRITE 100, "Test"
This is how:
TxT VAR Word
TxT = "Test"
WRITE 100, TxT
This doesn’t work so if anyone could help it would be appreciated?
This is what I try to do:
WRITE 100, "Test"
This is how:
TxT VAR Word
TxT = "Test"
WRITE 100, TxT
This doesn’t work so if anyone could help it would be appreciated?
Comments
So, there's the brute force approach:
Txt(4) VAR BYTE ' Declare a byte array
FOR I = 0 TO 3
LOOKUP I, [noparse][[/noparse]"T", "e", "s", "t"], Txt(I)
WRITE I, Txt(I) ' Write it to eeprom
NEXT
Now, if you KNOW what your string is, there's a much more direct approach:
MyText1 DATA "Test", 0
And a more 'complete', general purpose set of library code is attached.
Maybe I need to explain a little bit more. I want to check the battery and display the status (voltage) on a LCD. I found a very usefull and properly working code at: http://www.emesystems.com/BS2rct.htm
The variable Vx must be displayed as text and need to be placed between quotes. Otherwise intead of the value, the corresonding character will be displayed.
The subroutine will read the EEPROM at 100 and will write it the the LCD (44780)
BattChck:
LOW Batt
RCTIME Batt,0,rct
LOW Batt
Vx = 18150 / rct + -63
DEBUG HOME,DEC? rct,"Vx=",DEC Vx/10,".",DEC1 Vx
WRITE 100, Vx
GOSUB LCDwrmain
RETURN
Here is a super-simple example
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
So, your "WRITE 100, Vx" is going to wear out location 100 on the eeprom.
If you WANT to write a WORD value, you can do
WRITE 0, WORD Vx
or WRITE 0, Vx.LowByte
WRITE 1, Vx.HighByte
You keep talking about "writing to an LCD", then you wind up "Writing to an EEPROM". Since the EEPROM is not connected to the LCD, I don't know what you hope to achieve by writing to the eeprom.
There's ways to do what you're talking about, once we're certain what you're talking about.
Anyway, maybe writing to the eeprom isn't a good idea as you pointed out. I also want to display other things to the LCD so there will be a lot of writing to the eeprom.
Maybe anybody knows how to simply write to a LCD (44780) without using the eeprom? I've attached the eeprom version of the program for Controlling a LCD , which I used (copied from http://www.weethet.nl/english/basicstamp2_lcdcontrol.php#example1)
TempStr VAR BYTE(4)
TempVal VAR WORD
I VAR NIB
ValueWr:
FOR I = 0 TO 3
TempStr(I) = (TempVal // 10) + $30·· ' "$30" is ascii value of 'zero'
TempVal = TempVal / 10
NEXT
char = Quote
GOSUB LCDWr
FOR I = 3 TO 0
char = TempStr(I)
GOSUB LCDWr
NEXT
char = Quote
GOSUB LCDWr
RETURN
Converting a 'value' stored in memory to a string version of itself is one of those classic early computer science tasks. The pseudocode for this is:
Get the number into "TempVal"
WHILE TempVal is not zero, DO
The least significant character "Char" is "TempVal" MOD by 10.
Add the ascii value for "0" to "Char" to get the ascii value for the number "Char" represents.
Divide TempVal by 10.
END WHILE
The only thing I need to do is to figure out how to add your code and test... hope I'll have some time this evening [noparse]:)[/noparse]
Thanks..
This is what I've got so far, as you can see donno where to add your piece..
Otherwise -- what's not working?
In other words, what exactly IS the string that needs to be sent to the LCD?· Does it have leading and trailing quotes?· Is it JUST the Ascii characters of the value?
Sorry that I wasn't clear enough...hope I'm now?