LPC Demo Board Lessons
© 2005 Microchip Technology Inc. DS51556A-page 21
3.2.4.2 ADCON0
ADCON0 controls the ADC operation. Bit 0 turns on the ADC module. Bit 1 starts a
conversion and bits <5:2> selects which channel the ADC will operate. VCFG bit< 6>
selects the ADC reference, which may be either V
DD or a separate reference voltage
on V
REF. ADFM bit <7> selects whether the 10 bits are right or left justified in the 16 bits.
For purposes of this lesson, the ADC must be turned on and pointed to RA0. Choose
the internal voltage reference and 8T
OSC conversion clock.
The ADC needs about 5 μs, after changing channels, to allow the ADC sampling
capacitor to settle. Finally, we can start the conversion by setting the GO bit in ADCON0.
The bit also serves as the DONE
flag. That is, the ADC will clear the same bit when the
conversion is complete. The answer is then available in ADRESH:ADRESL.
This lesson takes the high order 4 bits of the result and copies them to the display LEDs
attached to PORTC.
See the Analog-to-Digital section in the PIC16F685/687/689/690 Data Sheet
(DS41262) for more details on the ADC module.
REGISTER 3-2: ADCON0 – A/D CONTROL REGISTER (ADDRESS: 1Fh)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
ADFM VCFG CHS3 CHS2 CHS1 CHS0 GO/DONE
ADON
bit 7 bit 0
bit 7 ADFM: A/D Result Formed Select bit
1 = Right justified
0 = Left justified
bit 6 VCFG: Voltage Reference bit
1 = V
REF pin
0 = V
DD
bit 5-2 CHS<3:0>: Analog Channel Select bits
0000 = Channel 00 (AN0)
0001 = Channel 01 (AN1)
0010 = Channel 02 (AN2)
0011 = Channel 03 (AN3)
0100 = Channel 04 (AN4)
0101 = Channel 05 (AN5)
0110 = Channel 06 (AN6)
0111 = Channel 07 (AN7)
1000 = Channel 08 (AN8)
1001 = Channel 09 (AN9)
1010 = Channel 10 (AN10)
1011 = Channel 11 (AN11)
1100 =CV
REF
1101 =VP6
1110 = Reserved. Do not use.
1111 = Reserved. Do not use.
bit 1 GO/DONE
: A/D Conversion Status bit
1 = A/D conversion cycle in progress. Setting this bit starts an A/D conversion cycle.
This bit is automatically cleared by hardware when the A/D conversion has completed.
0 = A/D conversion completed/not in progress
bit 0 ADON: A/D Enable bit
1 = A/D converter module is enabled
0 = A/D converter is shut off and consumes no operating current
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown