Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp — Parallax Forums

Basic Stamp

leshea2leshea2 Posts: 83
edited 2005-08-17 22:03 in BASIC Stamp
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, [noparse][[/noparse]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 !

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-10 20:53
    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, [noparse][[/noparse]char]
      LOOP
      RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • leshea2leshea2 Posts: 83
    edited 2005-08-10 21:50
    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 BakerPaul Baker Posts: 6,351
    edited 2005-08-10 22:16
    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 WilliamsJon Williams Posts: 6,491
    edited 2005-08-10 23:06
    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
  • leshea2leshea2 Posts: 83
    edited 2005-08-10 23:08
    I want this code, SEROUT Sout, Baud, [noparse][[/noparse]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 WilliamsJon Williams Posts: 6,491
    edited 2005-08-10 23:10
    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
  • leshea2leshea2 Posts: 83
    edited 2005-08-17 18:08
    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, [noparse][[/noparse]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, [noparse][[/noparse]char]
    LOOP
    RETURN
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-17 22:03
    This is a duplicate question -- please follow forum guidelines and refrain from cross-posting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.