Wixel SDK
adc.c
1 #include <cc2511_map.h>
2 #include <cc2511_types.h>
3 #include <adc.h>
4 
6 {
7  ADCIF = 0; // Clear the flag.
8  ADCCON3 = 0b10110000 ^ channel;
9  while(!ADCIF){}; // Wait for the reading to finish.
10 
11  if (ADCH & 0x80)
12  {
13  // Despite what the datasheet says, the result was negative.
14  return 0;
15  }
16  else
17  {
18  // Note: Despite what the datasheet says, bits 2 and 3 of ADCL are not
19  // always zero (they seem to be pretty random). We throw them away
20  // here.
21  return ADC >> 4;
22  }
23 }
24 
26 {
27  ADCIF = 0; // Clear the flag.
28  ADCCON3 = 0b10110000 ^ channel;
29  while(!ADCIF){}; // Wait for the reading to finish.
30 
31  return (int16)ADC >> 4;
32 }
signed short int16
Definition: cc2511_types.h:18
unsigned short uint16
Definition: cc2511_types.h:15
int16 adcReadDifferential(uint8 channel)
Definition: adc.c:25
unsigned char uint8
Definition: cc2511_types.h:9
uint16 adcRead(uint8 channel)
Definition: adc.c:5