
2002 Microchip Technology Inc.
DS41120B-page 111
PIC16C717/770/771
11.4
A/D Conversions
conversion. The port pins are configured as analog
inputs. The analog reference VREF+ is the device AVDD
and the analog reference VREF- is the device AVSS.
The A/D interrupt is enabled and the A/D conversion
clock is TRC. The conversion is performed on the AN0
channel.
EXAMPLE 11-1: PERFORMING AN A/D CONVERSION
BSF
STATUS, RP0
;Select Bank 1
CLRF
ADCON1
;Configure A/D Voltage Reference
MOVLW
0x01
MOVWF
ANSEL
;disable AN0 digital input buffer
MOVWF
TRISA
;RA0 is input mode
BSF
PIE1, ADIE
;Enable A/D interrupt
BCF
STATUS, RP0
;Select Bank 0
MOVLW
0xC1
;RC clock, A/D is on,
;Ch 0 is selected
MOVWF
ADCON0
;
BCF
PIR1, ADIF
;Clear A/D Int Flag
BSF
INTCON, PEIE
;Enable Peripheral
BSF
INTCON, GIE
;Enable All Interrupts
;
; Ensure that the required sampling time for the
; selected input channel has lapsed. Then the
; conversion may be started.
BSF
ADCON0, GO
;Start A/D Conversion
:
;The ADIF bit will be
;set and the GO/DONE bit
:
;cleared upon completion-
;of the A/D conversion.
; Wait for A/D completion and read ADRESH:ADRESL for result.