BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – COMPARE
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 141
COMPARE
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
COMPARE Mode, Variable
Function
Enable or disable comparator, compare voltages on P1 and P2 and retrieve
comparison result to store in Variable.
• Mode is a variable/constant/expression (0 – 2) that enables or
disables the comparator (input pins P1 and P2) and determines if the
optional comparator output pin (pin P0) is enabled or not. See Table
5.4 for an explanation of the Mode values.
• Variable is a variable (usually a bit) in which the comparison result is
stored.
Quick Facts
Table 5.4: COMPARE Quick
Facts.
BS2px
0: Disables comparato
r
1: Enables comparator with P0 as result output
Mode Values
2: Enables comparator without P0 as result output
0: Voltage P1 > P2; P0 optionally outputs 0
Variable Values
1: Voltage P1 < P2; P0 optionally outputs 1
Explanation
The COMPARE command enables or disables the built-in comparator
hardware on the BS2px’s I/O pins P0, P1, and P2. I/O pins P1 and P2 are
the comparator inputs and P0 is optionally the comparator result output
pin.
By default, the comparator feature is disabled. Using the COMPARE
command with a Mode argument of 1 or 2 enables the comparator feature
(using input pins P1 and P2) and returns the result of the comparison in
Variable. If Mode is 1, the result of the comparison is also output on I/O
pin P0. The following is an example of the COMPARE command:
Result VAR Bit
COMPARE 1, Result
This example enables the comparator (setting P0 to output the result, with
P1 and P2 as the comparator inputs) and writes the result of the
comparison into Result. Both Result and the output pin P0 will be 0 if the