#include <mega16.h>

#include <delay.h>

//#define ADC_VREF_TYPE 0xE0
#define ADC_VREF_TYPE 0xE0
//char temp=0;
//char temp2;
//char sum;
unsigned char adc_data;
// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{
//unsigned char adc_data;
// Read the 8 most significant bits
// of the AD conversion result
adc_data=ADCH;
// Place your code here
//PORTC=adc_data;

}

void main(void)
{
char temp;
char temp2;
char sub;
PORTA=0x00;
DDRA=0x00;

PORTB=0x00;
DDRB=0x00;

PORTC=0x00;
DDRC=0xFF;

PORTD=0x00;
DDRD=0x00;

MCUCR=0x00;
MCUCSR=0x80;
MCUCSR=0x80;

ACSR=0x80;
SFIOR=0x00;

ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x8C;
//ADCSRA=0x8E;

// Global enable interrupts
#asm("sei")

while (1)
      {
      // Place your code here
      ADMUX=0b11100000;//нулевой канал
      ADCSRA.6=1;//запуск ацп
      while(1)
        {
        if(ADCSRA.6==0) break;
        }
      temp=adc_data/4;  
           
      ADMUX=0b11100001;//первый канал
      ADCSRA.6=1;//запуск ацп
      while(1)
        {
        if(ADCSRA.6==0) break;
        }
      temp2=adc_data/4;
      sub=temp-temp2;
      PORTC=sub;
      };
}