Information
PIC16F62X
DS80073H-page 12 2000-2012 Microchip Technology Inc.
4. Module: Comparator
Example 9-1, “Initializing Comparator Module”, is
incorrect. The following code example should be
used instead.
EXAMPLE 1: INITIALIZING COMPARATOR MODULE
BCF INTCON,GIE ; Turn OFF Global Interrupts
BCF INTCON,PEIE ; Turn OFF Peripheral Interrupts
CLRF PORTA ; Init Port A
MOVLW 0X03 ; Init comparator mode
MOVWF CMCON ; CM<2:0> = 011
BSF STATUS,RP0 ; Select BANK 1
MOVLW 0x07 ; Initialize Port A Direction
MOVWF TRISA ; Set RA<2:0> as Inputs
; RA<4:3> as outputs
; TRIS<5> always reads '0'
BCF STATUS,RP0 ; Select BANK 0
CALL DELAY10 ; Wait 10us for comparator output to become valid
; See Table 17-1 Parameter 301
MOVF CMCON,F ; Read CMCON to end change condition
BCF PIR1,CMIF ; Clear pending interrupts
BSF STATUS,RP0 ; Select BANK 1
BSF PIE1,CMIE ; Enable Comparator Interrupts
BCF STATUS,RP0 ; Select BANK 0
BSF INTCON,PEIE ; Enable Peripheral Interrupts
BSF INTCON,GIE ; Global Interrupt Enable
; Insert Your code....
; Helper function is the Delay for 10us routine show below.
DELAY10 ; burns 8 cycles + the call for 10 cycles or 10us at 4Mhz
goto $+1 ; goto the next instruction and burn 2 cycles
call retlbl ; goto the next instruction and burn 2 more cycles
retlblreturn; go back and burn 2 cycles (actually done 2x for 4 cycles consumed)