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

Page 9

Advertising
background image

BASIC PROGRAMMING GUIDE

1-6

OPERATING MODES

Command and Run Modes
Basic operates in two modes, Command and Run.
Command mode is the direct, interactive mode
accessed when Basic is not running a program. The
Basic console prompt ">" indicates that Basic is
ready for Command mode input.

Run mode is when the processor is actively
executing a Basic program. Some commands (such
as SAVE, LIST, LOAD) can only be executed when
the processor is in command mode. Most Basic
instructions can be executed in either Command or
Run mode.

In Command mode, LOAD selects a Basic program
from the flash. The RUN command then causes the
selected program to execute. Within a Basic
program, the EXECUTE instruction is used to allow
the currently running program to call another stored
program. A number of programs may be available
to run depending upon the card and flash EPROM
size installed. Refer to your hardware manual for
more information.

Autorunning Programs
Programs may automatically load and run on
powerup or reset when FPROG2 is executed.

Stopping Program Execution
<Ctrl-C> halts the execution of a program and forces
the processor into Command mode (unless <Ctrl-C>
has been disabled). Operation can be resumed by
typing the CONT command. The STOP instruction
stops a running program; execution resumes with a
CONT command.

Sometimes it is desirable to not stop program
execution. To disable <Ctrl-C>, execute:

DBY(38) = DBY(38) .OR. 1

STORING PROGRAMS

Basic programs are stored in non-volatile flash type
EPROM on the CPU. The FPROG and PROG
commands are used to write programs.

OPERATORS

Operator categories include:

Arithmetic

=, +, *, /, **, SQR

Relational

=, <>, <, >, <=, >=

Logical

.AND., .OR., .XOR., .NOT.

Value

ABS, INT, PI, RND, SGN

Operator Precedence
The precedence of operators determines the order in
which mathematical operations are executed. Basic
scans an expression from left to right and performs
no operations until it encounters an operator of
lower or equal precedence. For instance,
multiplication takes precedence over addition.
Parenthetical expressions have the highest
precedence.

The following list is Basic's order of precedence:

1. Operators in parenthesis
2. Exponential operators (**)
3. Negation (-)
4. Multiplication (*) and division (/)
5. Addition (+) and Subtraction (-)
6.

Relational expressions (=, <>, <=, <, >=, >)

7. .AND. (logical AND)
8. .OR. (logical OR)
9. .XOR. (logical XOR)

Parenthetical expressions have the highest
precedence, so their use is a good way for you to
reduce ambiguity and make your programs more
readable. However, parenthetical expressions use
internal data memory.

ARITHMETIC OPERATORS

Arithmetic operators perform basic arithmetic
functions:

+

addition

-

subtraction, not negation

*

multiplication

/

division

**

exponential

Advertising