68a685e2aee932885820a0f727a8e9f243eb0818
[fw/sdcc] / device / include / pic16 / adc.h
1
2 /*
3  * A/D conversion module library header
4  *
5  * written by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
6  *
7  * Devices implemented:
8  *      PIC18F[24][45][28]
9  *
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 /*
27 ** $Id$
28 */
29
30 #ifndef __ADC_H__
31 #define __ADC_H__
32
33 /* link I/O libarary */
34 #pragma library io
35
36 /* interrupt on/off flag */
37 #define ADC_INT_OFF     0x00
38 #define ADC_INT_ON      0x01
39
40
41 /* output format */
42 #define ADC_FRM_RJUST   0x80
43 #define ADC_FRM_LJUST   0x00
44
45 /* oscillator frequency */
46 #define ADC_FOSC_2      0x00
47 #define ADC_FOSC_4      0x04
48 #define ADC_FOSC_8      0x01
49 #define ADC_FOSC_16     0x05
50 #define ADC_FOSC_32     0x02
51 #define ADC_FOSC_64     0x06
52 #define ADC_FOSC_RC     0x07
53
54
55 /* channel selection */
56 #define ADC_CHN_1               0x00
57 #define ADC_CHN_2               0x01
58 #define ADC_CHN_3               0x03
59 #define ADC_CHN_4               0x04
60 #define ADC_CHN_5               0x05
61 #define ADC_CHN_6               0x06
62 #define ADC_CHN_7               0x07
63
64
65 /* reference and pin configuration */
66 #define ADC_CFG_8A_0R   0x00
67 #define ADC_CFG_7A_1R   0x01
68 #define ADC_CFG_5A_0R   0x02
69 #define ADC_CFG_4A_1R   0x03
70 #define ADC_CFG_3A_0R   0x04
71 #define ADC_CFG_2A_1R   0x05
72 #define ADC_CFG_0A_0R   0x06
73 #define ADC_CFG_6A_2R   0x08
74 #define ADC_CFG_6A_0R   0x09
75 #define ADC_CFG_5A_1R   0x0a
76 #define ADC_CFG_4A_2R   0x0b
77 #define ADC_CFG_3A_2R   0x0c
78 #define ADC_CFG_2A_2R   0x0d
79 #define ADC_CFG_1A_0R   0x0e
80 #define ADC_CFG_1A_2R   0x0f
81
82
83 /* initialize AD module */
84 void adc_open(unsigned char channel, unsigned char fosc, unsigned char pcfg, unsigned char config);
85
86 /* shutdown AD module */
87 void adc_close(void);
88
89 /* begin a conversion */
90 void adc_conv(void);
91
92 /* return 1 if AD is performing a conversion, 0 if done */
93 char adc_busy(void) __naked;
94
95 /* get value of conversion */
96 int adc_read(void) __naked;
97
98 /* setup conversion channel */
99 void adc_setchannel(unsigned char channel) __naked;
100
101 #endif