Philips P89LPC902 Manuale Utente

Pagina di 114
Philips Semiconductors
User’s Manual - Preliminary -
P89LPC901/902/903
ANALOG COMPARATORS
2003 Dec 8     
78
an interrupt if the comparator interrupt is enabled. The user should therefore disable the comparator interrupt prior to disabling 
the comparator. Additionally, the user should clear the comparator flag, CMFx, after disabling the comparator.
Comparator and Power Reduction Modes
The comparator(s) may remain enabled when Power down or Idle mode is activated, but the comparator(s) are disabled 
automatically in Total Power down mode.
If the comparator interrupt is enabled (except in Total Power down mode), a change of the comparator output state will generate 
an interrupt and wake up the processor.
 If the comparator output to a pin is enabled, the pin should be configured in the push-pull mode in order to obtain fast switching 
times while in power down mode. The reason is that with the oscillator stopped, the temporary strong pullup that normally occurs 
during switching on a quasi-bidirectional port pin does not take place.
The comparator consumes power in Power down and Idle modes, as well as in the normal operating mode. This fact should be 
taken into account when system power consumption is an issue. To minimize power consumption, the user can disable the 
comparator via PCONA.5 or put the device in Total Power down mode.
Comparator Configuration Example
The code shown below is an example of initializing the comparator. This comparator  is configured to use the CMPREF inputs. 
The comparator output drives the CMP pin and generates an interrupt when the comparator output changes.
CMPINIT:
MOV
PT0AD,#030h
; Disable digital INPUTS on pins that are used 
; for analog functions: CIN, CMPREF.
ANL
P0M2,#0CFh
; Disable digital OUTPUTS on pins that are used
ORL
P0M1,#030h
; for analog functions: CIN, CMPREF.
MOV
CMP1,#024h
; Turn on comparator  and set up for:
; - Negative input from CMPREF pin.
; - Output to CMP pin enabled.
CALL
delay10us
; The comparator has to start up for at 
; least 10 microseconds before use.
ANL
CMP1,#0FEh
; Clear comparator interrupt flag.
SETB
EC
; Enable the comparator interrupt. The 
; priority is left at the current value.
SETB
EA
; Enable the interrupt system (if needed).
RET
; Return to caller.
The interrupt routine used for the comparator must clear the interrupt flag (CMF1 in this case) before returning.