If Then/Else Execution Sequence; Logical And Construction - Campbell CR510 Operator's Manual

Datalogger
Hide thumbs Also See for CR510:
Table of Contents

Advertisement

3.8.1 IF THEN/ELSE COMPARISONS
Program Control Instructions can be used for If
then/else comparisons. When Command 30
(Then do) is used with Instructions 83 or 88-92,
the If Instruction is followed immediately by
instructions to execute if the comparison is true.
The Else Instruction (94) is optional and is
followed by the instructions to execute if the
comparison is false. The End Instruction (95)
ends the If then/else comparison and marks the
beginning of the instructions that are executed
regardless of the outcome of the comparison
(see Figure 3.8-1).
FIGURE 3.8-1. If Then/Else
Execution Sequence
;Logical ELSE construction example:
;Check condition
1: If (X!F) (P89)
1:
1
X Loc [ DO_ppm ]
2:
4
<
3:
3.5
F
4
30
Then Do
;Instruction(s) to execute if above condition is true
2: Do (P86)
1:
41
Set Port 1 High
3: Else (P94)
;Instruction(s) to execute if above condition is false
4: Do (P86)
1:
51
Set Port 1 Low
5: End (P95)
SECTION 3. INSTRUCTION SET BASICS
FIGURE 3.8-2. Logical AND Construction
;Logical AND construction example:
;Check first condition
6: If (X!F) (P89)
1:
1
X Loc [ DO_ppm ]
2:
4
<
3:
3.5
F
4:
30
Then Do
;AND check second condition
7: If (X!F) (P89)
1:
2
X Loc [ Counter ]
2:
3
>=
3:
10
F
4:
30
Then Do
;Instruction(s) to execute if both conditions are true
8: Do (P86)
1:
41 Set Port 1 High
9: End (P95)
10: End (P95)
If Then/Else comparisons may be nested to
form logical AND or OR branching. Figure 3.8-
2 illustrates an AND construction. If conditions A
and B are true, the instructions included
between IF B and the first End Instruction will
be executed.
If either of the conditions is false, execution will
jump to the corresponding End Instruction,
skipping the instructions between.
A logical OR construction is also possible.
Figure 3.8-3 illustrates the instruction sequence
that will result in subroutine X being executed if
either A or B is true.
3-5

Advertisement

Table of Contents
loading

Table of Contents