* device/include/pic16/adc.h,
[fw/sdcc] / device / lib / pic16 / libio / adc / adcsetch.c
1
2 /*
3  * adcsetch - select convertion channel
4  *
5  * written by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
6  *
7  * Devices implemented:
8  *      PIC18F[24][45][28]
9  *      PIC18F2455-style
10  *
11  *
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.
16  *
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.
21  *
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.
25  *
26  * $Id$
27  */
28
29 #include <pic18fregs.h>
30 #include <adc.h>
31
32
33 void adc_setchannel(unsigned char channel) __naked
34 {
35 #if 0
36 #if defined(__SDCC_ADC_STYLE2455)
37   ADCON0 &= ~(0xf << 2);
38   ADCON0 |= channel << 2;
39 #else /* all other devices */
40   ADCON0 &= ~(0x7 << 3);
41   ADCON0 |= channel << 3;
42 #endif
43 #else
44   (void)channel;
45
46   __asm
47 #if defined(__SDCC_ADC_STYLE2455)
48     movlw       0xc3
49 #else /* all other devices */
50     movlw       0xc7
51 #endif
52     andwf       _ADCON0, f
53     
54     movlw       0x01
55     movf        _PLUSW1, w
56 #if defined(__SDCC_ADC_STYLE2455)
57 #else /* all other devices */
58     rlcf        _WREG, w
59 #endif
60     rlcf        _WREG, w
61     rlcf        _WREG, w
62
63     iorwf       _ADCON0, f
64
65     return
66   __endasm;
67 #endif    
68 }
69