3 * Internal ADCONVERTER Handler
4 * Copyright (C) 2013-06-20 K.Ohta <whatisthis.sowhat ai gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2,
9 * or (at your option) any later version.
10 * This library / program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this library; see the file COPYING. If not, write to the
17 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 * As a special exception, if you link this(includeed from sdcc) library
21 * with other files, some of which are compiled with SDCC,
22 * to produce an executable, this library does not by itself cause
23 * the resulting executable to be covered by the GNU General Public License.
24 * This exception does not however invalidate any other reasons why
25 * the executable file might be covered by the GNU General Public License.
33 #include <pic18fregs.h> /* ONLY FOR PIC18x */
45 extern void intadc_init(void);
46 extern unsigned int polladc(void);
48 extern void startadc(unsigned char ch);
49 extern unsigned int polladc2(void);
52 #define polladc2(a) { \
58 ADCON0bits.GO_DONE = 0; \
63 * ADCON1bits.VCFG1 = 0;
64 * ADCON1bits.VCFG0 = 0;
65 * ADCON2 = 0b10110110;
67 #define startadc(c) { \
68 adc_open(c, ADC_FOSC_64, 0, ADC_FRM_RJUST | ADC_INT_OFF | ADC_VCFG_VDD_VSS | ADC_NVCFG_VSS | ADC_PVCFG_VDD); \
73 #define polladc2(a) { \
82 * ADCON1bits.VCFG1 = 0;
83 * ADCON1bits.VCFG0 = 0;
84 * ADCON2 = 0b10110110;
86 #define startadc(c) { \
87 OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_20_TAD, (ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS & (0x0f << 2)) | (c << 2) , 0x0001 << c); \
93 extern unsigned int adc_rawtobatt(unsigned int b, unsigned int reflevel);
101 #endif /* ADC_INT_H */