3 * adcopen - initialize AD module
5 * written by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <pic18fregs.h>
34 * channel: one of ADC_CHN_*
35 * fosc: one of ADC_FOSC_*
36 * pcfg: one of ADC_CFG_*
37 * config: ADC_FRM_* | ADC_INT_*
40 void adc_open(unsigned char channel, unsigned char fosc, unsigned char pcfg, unsigned char config)
46 #if defined(__SDCC_ADC_STYLE2455)
47 ADCON0 |= (channel & 0x07) << 2;
48 #else /* all other devices */
49 ADCON0 |= (channel & 0x07) << 3;
53 #if defined(__SDCC_ADC_STYLE2455)
54 ADCON2 |= (fosc & 0x03);
55 #else /* all other devices */
56 ADCON0 |= (fosc & 0x03) << 6;
57 ADCON1 |= (fosc & 0x04) << 4;
60 /* setup reference and pins */
61 #if defined(__SDCC_ADC_STYLE2455)
62 ADCON1 |= pcfg & 0x3f;
63 #else /* all other devices */
64 ADCON1 |= pcfg & 0x0f;
67 #if defined(__SDCC_ADC_STYLE2455)
68 ADCON2 |= (config & ADC_FRM_RJUST);
69 #else /* all other devices */
70 ADCON1 |= (config & ADC_FRM_RJUST);
73 if (config & ADC_INT_ON) {
79 /* enable the A/D module */