OSDN Git Service

[UI][LCD] Fix flicking LCD display.
[openi2cradio/OpenI2CRadio.git] / adc_int.h
1 /*
2  * OpenI2CRADIO
3  * Internal ADCONVERTER Handler
4  * Copyright (C) 2013-06-20 K.Ohta <whatisthis.sowhat ai gmail.com>
5  *
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.
14  *
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,
18  *  MA 02110-1301, USA.
19  *
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.
26  */
27
28 #ifndef ADC_INT_H
29 #define ADC_INT_H
30
31 #if defined(__SDCC)
32 #include <sdcc-lib.h>
33 #include <pic18fregs.h> /* ONLY FOR PIC18x */
34 #endif
35 #include <adc.h>
36
37 #include "iodef.h"
38 #include "idle.h"
39 #include "ui.h"
40
41
42 #ifdef  __cplusplus
43 extern "C" {
44 #endif
45 extern void intadc_init(void);
46 extern unsigned int polladc(void);
47 #if 0
48 extern void startadc(unsigned char ch);
49 extern unsigned int polladc2(void);
50 #else
51 #ifdef __SDCC
52 #define polladc2(a) { \
53     while(adc_busy()); \
54     a = adc_read(); \
55     }
56
57 #define stopadc() { \
58     ADCON0bits.GO_DONE = 0; \
59     PIR1bits.ADIF = 0; \
60     PIE1bits.ADIE = 0; \
61     }
62 /*
63  *    ADCON1bits.VCFG1 = 0;
64  *    ADCON1bits.VCFG0 = 0;
65  *    ADCON2 = 0b10110110;
66  */
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); \
69     adc_setchannel(c); \
70     adc_conv(); \
71     }
72 #else
73 #define polladc2(a) { \
74     while(BusyADC()); \
75     a = ReadADC(); \
76     }
77
78 #define stopadc() { \
79     CloseADC(); \
80     }
81 /*
82  *    ADCON1bits.VCFG1 = 0;
83  *    ADCON1bits.VCFG0 = 0;
84  *    ADCON2 = 0b10110110;
85  */
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); \
88     ADCON0bits.GO = 1; \
89     }
90
91 #endif
92 #endif
93 extern unsigned int adc_rawtobatt(unsigned int b, unsigned int reflevel);
94
95
96
97 #ifdef  __cplusplus
98 }
99 #endif
100
101 #endif  /* ADC_INT_H */
102