SX User’s Manual Rev. 3.1 162 © 2000 Scenix Semiconductor, Inc. All rights reserved. www.scenix.com Chapter 7 Analog Comparator CMP_RES (Comparator Result). This bit determines the comparator result. A “1” indicates that
the voltage on RB2 is greater than the voltage on RB1, and a “0” indicates the opposite. The com-
parator must be already enabled (CMP_EN bit cleared to 0) in order to read a valid result.
Upon  power-up  or  reset,  the  CMP_EN  and  CMP_OE  bits  are  both  set  to  1.  This  means  that  the comparator starts in the disabled state. 7.2.1 Accessing the CMP_B Register Like all port configuration registers, the CMP_B register is accessed by the “mov !rx,W” instruction
in conjunction with an appropriate MODE register setting. For example, you can access the CMP_B
register using the following commands:
mov M,#$8 ;set MODE register to access CMP_B mov W,#$00 ;clear W mov !RB,W ;enable comparator and its output ... ;delay after enabling comparator for response mov M,#$8 ;set MODE register to access CMP_B mov W,#$00 ;clear W mov !RB,W ;enable comparator and its output and
;also read CMP_B (exchange W and CMB_B)
and W,#$01 ;set/clear Z flag based on comparator result snb $03.2 ;test Z flag in STATUS reg (0 => RB2<RB1) jmp rb2_hi ;jump only if RB2>RB1 ... To access the CMP_B register, you should load the MODE register with either 08h or 18h. The four
high-order bits of the MODE register are “don’t care” bits. The “mov M,#$8” instruction moves the
value 8h into the four low-order bit positions of the MODE register.
When you use the “MOV !RB,W” instruction to access the CMP_B register, it performs an exchange
of data between W and port control register. (An exchange of this type is performed only when you
access the CMP_B or WKPND_B register.) In the programming example above, the “MOV !RB,W”
instruction writes 00h into the CMP_B register, and simultaneously reads the contents of CMP_B into
W.
7.3 Comparator Operation Figure 7-1 is a block diagram showing the internal hardware of the comparator circuit. The two analog inputs to the comparator are the RB2 and RB1 pins. Operation of the comparator is enabled by the
CMP_RES bit and operation of the RB0 pin as the comparator output is enabled by the CMP_OE bit.
The comparator result appears in the CMP_RES bit position, whether or not the RB0 output pin is used
with the comparator. Read/write access to the CMP_B register is enabled when the MODE register
contains 08h or 18h.