© 2000 Scenix Semiconductor, Inc. All rights reserved. - 36 - www.scenix.com SX48BD/SX52BD/SX52BD75/SX52BD100 11.0 COMPARATOR The  device  contains  an  on-chip  differential  comparator. Ports  RB0-RB2  support  the  comparator.  Pins  RB1  and RB2  are  the  comparator  negative  and  positive  inputs, respectively, while RB0 serves as the comparator output pin. To use these pins in conjunction with the compara- tor,  the  user  program  must  configure  RB1  and  RB2  as inputs  and  RB0  as  an  output.  The  CMP_B  register  is used to enable the comparator, to read the output of the comparator  internally,  and  to  enable  the  output  of  the comparator to the comparator output pin.     The  comparator  enable  bits  are  set  to  “1”  upon  reset, thus  disabling  the  comparator.  To  avoid  drawing  addi- tional current during the power down mode, the compara- tor  should  be  disabled  before  entering  the  power  down mode. Here is an example of how to set up the compara- tor and read the CMP_B register. The  final  “mov”  instruction  in  this  example  performs  an exchange of data between the working register (W) and the  CMP_B  register.  This  exchange  occurs  only  with accesses  to  CMP_B  and  WKPEND_B.  Otherwise,  the “mov” instruction does not perform an exchange, but only moves data from the source to the destination. The following figure shows the format of the CMP_B reg- ister. CMP_B - Comparator Enable/Status Register ;enable RB0 as output mov mov W,#$18 M,W ;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 mov W,#$18 M,W ;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 CMP_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 ... CMP_EN CMP_OE Reserved CMP_RES Bit 7 Bit 6 Bits 5–1 Bit 0 CMP_EN When cleared to 0, enables the compar- ator. CMP_OE When cleared to 0, enables the compar- ator output to the RB0 pin if RB0 is con- figured as an output. CMP_RES Comparator result (Read Only): 1 for RB2>RB1 or 0 for RB2<RB1. Compara- tor must be enabled (CMP_EN = 0) to read the result. The result can be read whether or not the CMP_OE bit is cleared.