PDA

View Full Version : Command



leshea2
08-16-2005, 02:23 AM
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, ["Hello!", CR]· ' send the greeting
··· PAUSE 2500························· ' wait 2.5 seconds
· LOOP································· ' repeat forever
· END

Thanks !

Chris Savage
08-16-2005, 02:27 AM
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 (mailto:csavage@parallax.com)

leshea2
08-16-2005, 02:38 AM
So can I put a command inside of a CON, like "Call 18004459889 at 4:35 p.m.", ?

Thanks !

allanlane5
08-16-2005, 02:47 AM
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, [MyByte]
MyStr = MyStr + 1
READ MyStr, MyByte
LOOP
RETURN

leshea2
08-16-2005, 03:23 AM
I got everything except this part of the code,
MyStr = MyStr + 1
READ MyStr, MyByte

Thanks !

Chris Savage
08-16-2005, 04:06 AM
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 (mailto:csavage@parallax.com)

leshea2
08-16-2005, 04:47 AM
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, [MyByte], ?

Thanks !

allanlane5
08-16-2005, 05:47 AM
"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 ..."