Rev Author Line No. Line
2116 paro 1 #include "adc.h"
2  
3 #include <avr/io.h>
4  
5 void AD_Init_Interrupt() {
6 ADMUX = 0b01000000; // PORTC_0,Vref=V_ACC,capacitor on AVREF
7  
8 ADCSRA = (0b00000011); // 8 Prescaling
9 ADCSRA |= (1 << ADFR); // Set ADC to Free-Running Mode
10 ADCSRA |= (1 << ADIE); // enable interrupt
11 // sei();
12 ADCSRA |= (1 << ADEN); // Enable ADC
13 ADCSRA |= (1 << ADSC); // Start A2D Conversions
14 }
15  
16  
17 void AD_Init() {
18 ADMUX = 0b01000000; // PORTC_0,Vref=Vacc with cap. on ref.
19  
20 ADCSRA |= (0b00000101); // 32 Prescaling
21 ADCSRA |= (1 << ADFR); // Set ADC to Free-Running Mode
22 ADCSRA |= (1 << ADEN); // Enable ADC
23 ADCSRA |= (1 << ADSC); // Start A2D Conversions
24 }
25  
26  
27 unsigned char AD_Read() {
28 char val;
29 val=(ADCL>>2); // low must be read first!! see datasheet...
30 val|=(ADCH<<6);
31 return val;
32 }