На вот в качестве гуманитарной помощи. Сервис вставляется в прерывание 1 мс.
unsigned char adc_values[6];
unsigned char adc_channel;
unsigned char adc_ready=0;
void AdcConfiguration(void)
{
ADCSRA =
(1 << ADEN) | //ADC ON,
// ADSC not start conversion
// ADATE auto trigger disable
(1 << ADIF) | // clear conversion flag writing 1 to it
// ADIE interrupt disable
(1 << ADPS2) | //prescaler =64 (ADPS2=1, ADPS1=1, ADPS0=0)
(1 << ADPS1) |
// ADPS0
0;
ADMUX = //REFS1 |
(1 << REFS0) | // REFerence = AVCC with C on pin Vref (REFS1=0, REFS0=1)
(1 << ADLAR) | // left adjust results - read high byte only
0;
}
#define ADCoff ADCSR=0
#define SetAdcChannel(mux) ADMUX = (0xE0 & ADMUX) | (mux)
#define StartAdcConversion() ADCSRA |= (1 << ADIF) | (1 << ADSC)
#define AdcConversionComplete (!(ADCSRA & (1 << ADSC)))
void AdcService(void)
{
static char adc_status;
switch (adc_status)
{
case 0:
AdcConfiguration();
SetAdcChannel(adc_channel = 0);
StartAdcConversion();
adc_status = 1;
break;
case 1:
if (AdcConversionComplete)
{
adc_values[adc_channel] = ADCH;
if (++adc_channel >= COUNT_ELEMENTS(adc_values))
{
adc_channel = 0;
adc_ready = 1;
}
SetAdcChannel(adc_channel);
StartAdcConversion();
}
break;
default:
adc_status = 0;
}
}