Basic programming guide – Remote Processing BASIC for the CX-10 Modbus User Manual

Page 7

Advertising
background image

BASIC PROGRAMMING GUIDE

1-4

Names are identified by the first and last characters
and its length. Identical length names with identical
first and last characters are considered the same.
PUMP_42 and PRIMER2 are considered the same.
The way to correct this is to change the name length
or first or last character.

Variable names longer than two characters require
more time to process. Once a variable name is
declared, it can only be erased by the CLEAR
statement or by LOADing in a new program.

It is possible to have variable names longer than 8
characters. A problem is the name length is stored
partly as a modulo 256 number. What it boils down
to is a variable may or may not be recognized as
unique. The Basic considers FEED_BIN_01 and
FEED_BIN_11 as the same variable.

The original BASIC-52 had a bug where the variable
name 'F' was erased if it was the last letter in a
variable followed by a space. Basic corrected this.

Watch out for commands embedded in variable
names. FORM_5 contains the command FOR. A
BAD SYNTAX error is usually returned in these
instances. The statement FORM_5=BOTTOM does
not return an error but interprets it as

FOR M_5=BOT TO M

The key is to look at your statements as they are
printed on the screen and make sure they are what
you intended.

Valid variables names are:

CA5,

DA15_679,

PUMP_A, VALVE02,

A(10),

SIZE(5),

ABC_

Invalid variables, which may include embedded
commands include:

4C,

C$0,

GOTOE,

FORM,

#XYZ,

_ABC

Constants are literal values. These are "known"
values as opposed to variables which can be
assigned any value, usually by a function. Constants
may be numeric or string. To Basic-52, there is no
difference between the two.

Constants are expressed as integer, decimal,
hexadecimal or exponential floating-point. The
range of valid values are:

± 1E-127 to ± .99999999e+127

Using constants instead of a number speeds up
execution by at least 5%. For example, use

10 CH = 5
20 A = REGREAD(CH)

instead of

20 A = REGREAD(5)

Variables and constants are expressed as follows:

A = 5

Integer format

A = 5.3

Decimal format

A = 0ACH

Hexadecimal format

A = 1.4E3

Exponential

Basic supports eight significant digits plus and
exponent and truncates any extra digits.
Hexadecimal constants with a leading alpha
character must be preceded by a leading zero. If you
fail to do this, Basic interprets them as variable
names.

All hexadecimal constants are followed by a trailing
"H" (0FFH for example). A "0" prefix is necessary
when the first number is a letter (A-F).

Certain logical operators, such as .NOT., .AND.,
.XOR., and .OR., assume a 16-bit argument such as
0FFFFH. If you supply fewer than 16 bits, it returns
a 16-bit value based on the assumption the
unsupplied most significant bits are zero.

Subroutines
Use of subroutines tends to make programming
more modular and easier to follow. The number of
subroutines is limited to the amount of internal stack
space. Usually this is about 35 subroutines, but can
go down if FOR-NEXT loops are active. This is
sufficient to handle all multi-tasking and several
levels of subroutines.

Most complex programs tend to have a maximum of
7 nested subroutine levels. Usually the maximum is
4.

Addresses
Addresses are specified as either decimal or
hexadecimal numbers. Hexadecimal addresses with
a leading alpha character need a preceding zero
otherwise they will be interpreted as variable names.

Arrays
Arrays are single dimension and start with element
0. They are dimensioned using the DIM statement.

Advertising