16FXlib
adc.c
Go to the documentation of this file.
1 
2 //*****************************************************************************
3 // Author : Christian Illy
4 // Created : 20.04.2009
5 // Revised : 29.06.2009
6 // Version : 0.1
7 // Target MCU : Fujitsu MB96300 series
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 //*****************************************************************************
23 
24 #include "mb96348hs.h"
25 #include "util.h"
26 #include "adc.h"
27 #include "adc.cfg.h"
28 
29 void adc_init(void) {
30  // Stop Mode (MD = 11), 8 bit resolution
32  ADER0 = ADC_PIN_MASK;
33 }
34 
36  uint8_t result = 0;
37  if (_BV(pin) & ADC_PIN_MASK) {
38  // Setting Register = 011011.......... = 0x6C00 + start address (5 bit) + end address (5 bit)
39  ADSR = 0x6c00 | (pin << 5) | pin;
40  ADCS |= _BV(ADC_ADCS_STRT) | _BV(ADC_ADCS_BUSY); // start ADC
41  while ((ADCS & _BV(ADC_ADCS_INT)) == 0);
42  result = ADCR;
43  ADCS &= ~_BV(ADC_ADCS_INT);
44  return result;
45  }
46  return -1;
47 }
#define ADC_ADCS_MD1
ADC converter mode 1.
Definition: adc.cfg.h:48
#define ADC_ADCS_STRT
ADC start conversion.
Definition: adc.cfg.h:46
#define _BV(bit)
Definition: util.h:39
unsigned char uint8_t
Definition: inttypes.h:35
#define ADC_PIN_MASK
ADC usable pins mask.
Definition: adc.cfg.h:55
int int16_t
Definition: inttypes.h:55
#define ADC_ADCS_BUSY
ADC busy bit. 1 while conversion is running. Write to 0 to force stop conversion. ...
Definition: adc.cfg.h:34
#define ADC_ADCS_S10
ADC 8 bit mode.
Definition: adc.cfg.h:52
int16_t adc_getValue(uint8_t pin)
Definition: adc.c:35
void adc_init(void)
Definition: adc.c:29
#define ADC_ADCS_INT
ADC interrupt flag.
Definition: adc.cfg.h:36
#define ADC_ADCS_MD0
ADC converter mode 0.
Definition: adc.cfg.h:50