Download Datasheet

Transcript
smart BASIC
User Manual
The smart BASIC implementation consists of a command parser and a single line/single pass
compiler. It takes each line of text (a series of tokens and depending on their content and its
operating mode) and does one of the following:

Act on them immediately (such as with AT commands).

Optionally, if the build includes the compiler, generate a compiled output which is stored
and processed at a later time by the run-time engine. This capability is not present in the
BL600 due to flash memory constraint.
smart BASIC has been designed to work on embedded systems where there is often a very
limited amount of RAM. To make it efficient, you need to declare every variable that you intend
to use by using the DIM statement; the compiler can then allocate the appropriate amount of
memory space. In the following example program, we are using the variable “i” to count how
many times we print “Hello World”.
smart BASIC allows a couple of different variables types, numbers (32 bit signed integers) and
strings.
Our program (stored in a file called HelloWorld.sb’) looks like this:
'Example Script "helloworld"
DIM i as integer
'declare our variable
for i=1 to 10
print "Hello World \n"
next
'Perform the print ten times
'The \n forces a new line each time
'Increment the value of i
We have introduced a few new things, the first being comments. Any line that starts with an
apostrophe ‘ is ignored by the compiler from the token onwards and treated as a comment, so
the opening line is ignored. You can also add comments to a program line by adding an
apostrophe proceeded by a space to start the comment.
If you have ‘C++’ language experience, you can also use the // token to indicate that the rest
of the line is a comment.
The second item of interest is the line feed character ‘\n’ which we’ve added after Hello World
in the print statement. This tells the print command to start a new line. If left out, the ten Hello
World’s would have been concatenated together on the screen. You can try removing it to see
what would happen.
Compile and download the file HelloWorld.sb to the module (using XCompile+Load in
UwTerminal) and then run the application in the usual way:
AT+RUN “helloworld”
You’ll see the following screen output:
at+run "helloworld"
Hello
Hello
Hello
Hello
Hello
Hello
World
World
World
World
World
World
www.lairdtech.com
24
Laird Technologies