Shop OBEX P1 Docs P2 Docs Learn Events
Command — Parallax Forums

Command

leshea2leshea2 Posts: 83
edited 2005-08-15 21:47 in BASIC Stamp
I know that VAR is used to store data, but what is CON used for, for an example·in a·code like this,


' {$STAMP BS2}
' {$PBASIC 2.5}


SO············· PIN···· 1·············· ' serial output
FC············· PIN···· 0·············· ' flow control pin
#SELECT $STAMP
· #CASE BS2, BS2E, BS2PE
··· T1200······ CON···· 813
··· T2400······ CON···· 396
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
··· T38K4······ CON···· 6
· #CASE BS2SX, BS2P
··· T1200······ CON···· 2063
··· T2400······ CON···· 1021
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
··· T38K4······ CON···· 45
· #CASE BS2PX
··· T1200······ CON···· 3313
··· T2400······ CON···· 1646
··· T9600······ CON···· 396
··· T19K2······ CON···· 188
··· T38K4······ CON···· 84
#ENDSELECT
Inverted······· CON···· $4000
Open··········· CON···· $8000
Baud··········· CON···· T38K4 + Inverted

Main:
· DO
··· SEROUT SO\FC, Baud, [noparse][[/noparse]"Hello!", CR]· ' send the greeting
··· PAUSE 2500························· ' wait 2.5 seconds
· LOOP································· ' repeat forever
· END

Thanks !

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-15 18:27
    Hello,

    ·· CON is used to define constants.· Values that don't change.· These can replace constant values in your code with meaningful descriptions, also making it easy to make code changes.· If you change the value in the Constant, all uses of it are affected.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • leshea2leshea2 Posts: 83
    edited 2005-08-15 18:38
    So can I put a command inside of a CON, like "Call 18004459889 at 4:35 p.m.", ?

    Thanks !
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-08-15 18:47
    No, 'CON' does not support 'strings'.

    But you can do:
    DATA String1, "Call 18004459889 at 4:35 P.M.", 0
    MyStr VAR WORD
    MyByte VAR BYTE

    MAIN:

    MyStr = String1
    GOSUB OutputString
    Pause 100
    GOTO MAIN

    OutputString:
    READ MyStr, MyByte
    DO WHILE·MyByte <> 0
    SEROUT 16, 16384, [noparse][[/noparse]MyByte]
    MyStr = MyStr + 1
    READ MyStr, MyByte
    LOOP
    RETURN
  • leshea2leshea2 Posts: 83
    edited 2005-08-15 19:23
    I got everything except this part of the code,
    MyStr = MyStr + 1
    READ MyStr, MyByte

    Thanks !
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-15 20:06
    MyStr is referring to the variable which which holds the address offset of the next byte of data read from the EEPROM.· MyByte is the variable holding the value read from EEPROM. MyStr is incremented to fetch the next value.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • leshea2leshea2 Posts: 83
    edited 2005-08-15 20:47
    So would I need this part of this code,
    MyStr = MyStr + 1
    READ MyStr, MyByte,
    if I wanted to end the code at
    SEROUT 16, 16384, [noparse][[/noparse]MyByte], ?

    Thanks !
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-08-15 21:47
    "MyStr" only holds the address of a byte of the string, as it is stored in the eeprom.

    "MyByte" then gets the value of the BYTE (a single byte) with each READ.
    Then the single byte is output, using the SEROUT command.
    This process repeats, until MyByte is loaded with that 'zero' value at the end of the string.

    If you don't want to output the entire string, and want to output only the first byte, then certainly you can end the code after the SEROUT. But a single byte string, like "C", is not very useful when you wanted to output "Call ..."
Sign In or Register to comment.