Section 9. Programming
89
The following commands and logical operators are used to construct logical
expressions.
CRBASIC EXAMPLE. Logical Expression Examples
p. 89
demonstrate some logical expressions.
• IF
• AND
• OR
• NOT
• XOR
• IIF
Table 11.
Logical Expression Examples
If X >= 5 then Y = 0
Sets the variable Y to 0 if the expression "X >= 5" is true, i.e. if X is greater than or equal to 5. The CR200(X) evaluates
the expression (X >= 5) and registers in system memory a -1 if the expression is true, or a 0 if the expression is false.
If X >= 5 OR Z = 2 then Y = 0
Sets Y = 0 if either X >= 5 or Z = 2 is true.
If X >= 5 AND Z = 2 then Y = 0
Sets Y = 0 only if both X >= 5 and Z = 2 are true.
If 6 then Y = 0.
"If 6" is true since "6" (a non-zero number) is returned, so Y is set to 0 every time the statement is executed.
If 0 then Y = 0.
"If 0" is false since "0" is returned, so Y will never be set to 0 by this statement.
Z = (X > Y).
Z will equal -1 if X > Y, or Z will equal 0 if X <= Y.
The NOT operator simply complements every bit in the word. A Boolean can only be 0 or have all of its bits set to 1.
Complementing a Boolean will turn TRUE (all bits set) to FALSE (all bits complemented to 0). Since the CR200(X)
cannot declare a variable to be a Boolean data type, IIF is used to force the logical results to either 0 or -1.
Example Program
'(a AND b) = (26 AND 26) = (&b11010 AND &b11010) =
'&b11010. NOT (&b11010) yields &b00101.
'This is non-zero, so when converted to a
'BOOLEAN, it becomes TRUE.
Public a
Public b
Public is_true
Public not_is_true
Public not_a_and_b
BeginProg
a = 26
b = a
Scan (1,Sec)
is_true = IIF(a AND b = 0,0,-1)
'This evaluates to TRUE.
not_is_true = IIF(NOT (is_true) = 0,0,-1)
'This evaluates to FALSE.
not_a_and_b = IIF(NOT (a AND b) = 0,0,-1)
'This evaluates to TRUE!
NextScan
EndProg
Summary of Contents for CR200
Page 32: ...Section 2 Quickstart Tutorial 22 ...
Page 45: ...Section 3 Overview 35 3 3 Specifications ...
Page 46: ...Section 3 Overview 36 ...
Page 58: ...Section 4 Sensor Support 48 ...
Page 62: ...Section 5 Measurement and Control Peripherals 52 ...
Page 78: ...Section 8 CR200 X Configuration 68 ...
Page 102: ...Section 9 Programming 92 ...
Page 138: ...Section 11 Programming Resource Library 128 ...
Page 156: ...Section 16 Support Software 146 ...
Page 160: ...Section 17 Care and Maintenance 150 ...
Page 167: ...Section 18 Troubleshooting 157 18 3 3 2 Charging Circuit Test Solar Panel ...
Page 168: ...Section 18 Troubleshooting 158 18 3 3 3 Charging Circuit Test Transformer ...
Page 169: ...Section 18 Troubleshooting 159 18 3 3 4 Adjusting Charging Circuit Voltage ...
Page 170: ...Section 18 Troubleshooting 160 ...
Page 184: ...Appendix A Glossary 14 ...
Page 190: ...Appendix B Status Table and Settings 20 ...
Page 192: ...Appendix C Serial Port Pin Outs 22 ...
Page 211: ......