PDA

View Full Version : Basic Stamp



leshea2
08-11-2005, 04:28 AM
Hi, can anyone tell me·what's wrong with·this command and how I could fix it·?

' {$STAMP BS2sx}
' {$PBASIC 2.5}

KAA DATA "Call 18004459889 at 4:35 p.m."

MAR······ VAR······ Word
counter·· VAR······ Byte
R········ PIN······ 0
FOR counter = 1 TO 1
PAUSE 1000
READ KAA, MAR
NEXT
SEROUT R, 17405, [MAR]
END

I'm trying to·get the basic stamp to serout that code to another device to program it the device to do·as the code·says.

Thanks in advance !

Jon Williams
08-11-2005, 04:53 AM
Give this version a try -- it corrects several boo-boos and makes the code easier to update and use with other messages.



' {$STAMP BS2sx}
' {$PBASIC 2.5}

Sout PIN 0

Baud CON 17405

eePntr VAR Word
char VAR Byte

Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


Main:
eePntr = Msg1
GOSUB Send_Msg
END


Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP
RETURN

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

leshea2
08-11-2005, 05:50 AM
Thanks a lot for your help !

But can you tell me why you added the 0 to the data command, and also, would I need to use the else command after IF (char = 0) THEN EXIT, ?

Again, thanks !

Paul Baker
08-11-2005, 06:16 AM
A value of 0 is called a "null" and is used to denote the end of a string (the text in quotes), when the 0 is encountered the string has been completed and the DO...LOOP is EXITed. An ELSE is not required in this instance because the EXIT skips the program execution to the command following the LOOP (RETURN in this instance) so when char=0 the code following the IF statement is not executed.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10

Jon Williams
08-11-2005, 07:06 AM
Paul covered all the tech stuff; the practical reason for storing messages like that in z-String format is that the Send_Msg subroutine only needs to know where a message starts (you put that into eePntr) -- the 0 terminator allows that subroutine to "print" a string of any length without knowing ind advance what that length is.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

leshea2
08-11-2005, 07:08 AM
I want this code, SEROUT Sout, Baud, [char], to be executed, so will the above execute the SEROUT Sout, Baud ? I mean will the stamp serout "Call 18004459889 at 4:35 p.m.", 0, to another device ?


Thanks !

Jon Williams
08-11-2005, 07:10 AM
Yes, it does it in the subroutine called Send_Msg. You can use that same subroutine to send other messages (you just have to point to the message before calling the subroutine).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

leshea2
08-18-2005, 02:08 AM
How would I add another line of code to this command, if I want to make the BS2sx stamp flash an LED on and off once, to confirm the this part of the code,

Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP
RETURN


was successful executed ?

Thanks !


' {$STAMP BS2sx}
' {$PBASIC 2.5}

Sout PIN 0

Baud CON 17405

eePntr VAR Word
char VAR Byte

Msg1 DATA "Call 18004459889 at 4:35 p.m.", 0


Main:
eePntr = Msg1
GOSUB Send_Msg
END


Send_Msg:
DO
READ eePntr, char
eePntr = eePntr + 1
IF (char = 0) THEN EXIT
SEROUT Sout, Baud, [char]
LOOP
RETURN

Jon Williams
08-18-2005, 06:03 AM
This is a duplicate question -- please follow forum guidelines and refrain from cross-posting.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax