;------------------------CONFIGURA ADC-----------
CLR ADPCFG ; Configure A/D port,
MOV #0xFFEF,W2
MOV W2,ADPCFG
MOV #0x0000,W2
MOV W2,ADCON1 ; Configure sample clock source
; and conversion trigger mode.
; Unsigned ENTERO format,
; Manual conversion trigger,
; Manual start of sampling,
; No operation in IDLE mode.
CLR ADCON2 ; Configure A/D voltage reference
MOV #0x0000,W2
MOV W2,ADCON2
CLR ADCON3 ; Configure A/D conversion clock
MOV #0x0100,W2
MOV W2,ADCON3
CLR ADCHS ; Configure input channels,
MOV #0x0004,W2
MOV W2,ADCHS
CLR ADCSSL ; No inputs are scanned.
BCLR IFS0,#ADIF ; Clear A/D conversion interrupt flag
; Configure A/D interrupt priority bits (ADIP<2:0>) here, if
; required. (default priority level is 4)
BCLR IPC2, #ADIP0 ; Setup ADC interrupt for
BSET IPC2, #ADIP1 ; desired priority level
BCLR IPC2, #ADIP2 ; (this example assigns level 2 priority)
BSET IEC0,#ADIE ; Enable A/D conversion interrupt
BSET ADCON1,#SSRC0
BSET ADCON1,#SSRC1
BSET ADCON1,#SSRC2
BSET ADCON3,#ADRC ; A/D internal RC clock
;BSET ADCON1,#ASAM
;BSET ADCON1,#ADON ; Turn on A/D
;BSET ADCON1,#SAMP ; Start sampling the input