/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.8d Professional
Automatic Program Generator
© Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 09.04.2010
Author  : F4CG                            
Company : F4CG                            
Comments: 


Chip type           : ATmega8
Program type        : Application
Clock frequency     : 8,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/
#include <mega8.h>
#include <delay.h> 


#define ON      PORTD.0 
#define INC     PORTD.1 
#define DEC     PORTD.2 
#define OFF     PORTD.3 
#define CRUISE  PORTD.4  

bit temp = 0; 
bit cruise = 0;

#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 0
unsigned char adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
#define ADC_VREF_TYPE 0x20 

interrupt [ADC_INT] void adc_isr(void)
{
static unsigned char input_index=0;
// Read the 8 most significant bits
// of the AD conversion result
adc_data[input_index]=ADCH;
// Select next ADC input
if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
input_index=0;
ADMUX=(FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff))+input_index;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
 
/************ Êíîïêà ON/OFF **************/
if (adc_data[0] < 0x10)
    {      
    if (!temp)CRUISE = cruise = !cruise; 
    temp = 1; 
    if (cruise)ON = 1;     
    else OFF = 1;   
    return;
    }
else
    { 
    /************ Êíîïêà SET ********************/   
    if ((adc_data[0] > 0x30) && (adc_data[0] < 0x40))
        {      
        ON = 1;
        return;
        }
    else
        {
        temp = 0;
        ON = OFF = 0;     
        }
    }
/******************************************/    
/************ Êíîïêà + ********************/
if ((adc_data[0] > 0x10) && (adc_data[0] < 0x20))
    {      
    INC = 1;
    return;
    }
else INC = 0;
/******************************************/ 
/************ Êíîïêà - ********************/
if ((adc_data[0] > 0x21) && (adc_data[0] < 0x30))
    {      
    DEC = 1;
    return;
    }
else DEC = 0;
/******************************************/ 
}     


void main(void)
{
PORTD=0x00;
DDRD=0xFF;

ADMUX=FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff);
ADCSRA=0xCC;
#asm("sei")

while (1)
{

};
} 