Storing text sentences in variables.
Clock Loop
Posts: 2,069
I feel stoopid asking this, but I have searched the forum, and the nuts and volts, and the stampworks, and the help file for anything related to working with text sentences. I can only find DEBUG use of sentences, and can only find EEPROM using sentences. I dont see any examples of storing sentences in a variable.
Why doesn't this work?
I am guessing it has to do with the length of the variable, and the length of the sentence. So how DO I store sentences in variables?
[noparse]:)[/noparse]
Why doesn't this work?
' {$STAMP BS2} ' {$PBASIC 2.5} test VAR Word Main: test = "hello how are you" DEBUG test
I am guessing it has to do with the length of the variable, and the length of the sentence. So how DO I store sentences in variables?
[noparse]:)[/noparse]
Comments
Now, in a line like:
SEROUT 16, I9600, [noparse][[/noparse]"Hello, how are you?", 13]
the bytes "Hello..." are actually stored in the EEPROM. You have 2 KBytes of eeprom, so this works well.
I suppose you could do:
String1 CON "Hello there"
SEROUT 16, I9600, [noparse][[/noparse]String1,13] ' This sends the string "Hello there" out the serial port.
Except CON statements don't support strings. Oh well.
Or, I COULD store it one letter at a time.. LOL
Thanks guys.
Then this code MUST use eeprom to store its text! right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
'---- Code
' {$STAMP BS2}
' {$PBASIC 2.5}
String1 DATA "Hello There",0
I9600·· CON 16468· ' 84 + 16384, or 9600 baud, Inverted
MAIN:
· SEROUT 16, I9600, [noparse][[/noparse]String1,13]
· PAUSE 200
· GOTO MAIN
The question is, how do you put in the SEROUT statement a 'reference' to String1 that will result in the string being output.· One workaround is a subroutine that will read the data a byte at a time and send it with a SEROUT for each byte.· Is there an easier way?
·
' {$STAMP BS2}
' {$PBASIC 2.5}
String1 DATA "Hello There",0
StringLoc VAR Word· ' 1..2000
MyByte··· VAR Byte
I9600·· CON 16468 '16384 + 84
MAIN:
· ' SEROUT 16, I9600, [noparse][[/noparse]String1,13]· ' This doesn't work...
· ' Hopefully, this does...
· StringLoc = String1
· GOSUB SendString
· PAUSE 200
· GOTO MAIN
SendString:
· READ StringLoc, MyByte
· IF MyByte <> 0 THEN
··· SEROUT 16, I9600, [noparse][[/noparse]MyByte]
··· StringLoc = StringLoc + 1
··· GOTO SendString
· ENDIF
· RETURN
·
You can, of course, implement it yourself -- here's my version of your subroutine:
Print_Str:
· DO
··· READ eePntr, char
··· IF (char = 0) THEN EXIT
··· SEROUT SPin, Baud, [noparse][[/noparse]char]
··· eePntr = eePntr + 1
· LOOP
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 7/4/2005 7:49:27 PM GMT
Though "eePntr" would actually be my "StringLoc" WORD variable.
And "char" would be MyByte.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
i use simular code with this line to read tabled text.
offset points to one data set
eePntr points to the line you wish to print
idx points to the chacter of the line of the dataset
it just makes organizing large tables of data easier; for me anyway.
ROX ON
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Byte walks into a bar and orders a pint. Bartender asks him "What's wrong?"
Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off."