3 Phasen Relais

#include <avr/io.h>
#include <avr/interrupt.h>
#define TAKT 1000000UL


//Taster

#define Taster(port,pin,taster,operation,time_P,entprellzeit,operation2,operation3)       \
({                                     			\
												\
	   if ( taster == 0) 						\
	   {										\
			     								\
		   if ( port & (1<< pin )) 				\
	       { 									\
												\
			 						            \
		     taster = 1;						\
			 time_P = 0;                        \
                         						\
		   }									\
	   }										\
	                                            \
	   if ( taster == 1)                        \
       { 										\
			if (time_P >= entprellzeit)			\
		   {                                    \
			    if ( port & (1<< pin ))         \
               {                                \
                                                \
                                                \
                 operation;                     \
                 gelaufen = 0;                  \
                 taster = 2;                    \
				                                \
               }                                \
                else                            \
			   {                                \
                                                \
                  taster = 0;                   \
	           }                                \
												\
           }									\
	   }                                        \
												\
												\
												\
	     										\
	   if ( taster == 2)						\
	   {										\
           if (!( port & (1<< pin )))		    \
	       {								    \
		     taster = 0;                        \
             operation2; 					    \
			             operation3; 					    \
                                                \
		   }                                    \
	   }                                             \
})                                       


//Variablen



unsigned int volatile laufzeit;
unsigned int volatile gelaufen;
unsigned char volatile time_Pa;
unsigned char volatile time_Pb;
unsigned char volatile tastera;
unsigned char volatile tasterb;
unsigned char volatile Motor_start;
unsigned char volatile Motor_wait_start;


//Hauptschleife

int main(void)
{       

  ADMUX = 0x02;
  ADCSRA = 0xc7;
  
  TCCR0B = 0x05;
  TIMSK0 |= (1 << TOIE0);
  sei();
 
  
 
  DDRB = 0x04;
  
 
   while(1)
   {
      
	 Taster(PINB,PINB1,tastera,Motor_wait_start = 1,time_Pa,80,,);
	 Taster(PINB,PINB3,tasterb,Motor_start = 1,time_Pb,15,Motor_start = 0,Motor_wait_start = 0);
	 
	  
	   while (ADCSRA & (1<<ADSC) );
	   {
	     
	   }
	   
	   
	 laufzeit = (4 * ADCW);
	    if (laufzeit <= 200)
	   {
		 
		 laufzeit = 200;
		 
	   }
	 
	 
	 ADCSRA |= (1<<ADSC);
	 
      
     
   }  
}

// Timer Überlauf



SIGNAL (SIG_OVERFLOW0)
{

  TCNT0 = 235;
	
  time_Pa++;
  time_Pb++;
  gelaufen++;
  
  
  
  
  
  
      if (Motor_wait_start == 1)
   {
     
	 Motor_start = 1;
	 
	 
	    if (gelaufen >= laufzeit)
	   { 
		 
		 Motor_start = 0;
		 
	   }
	 
   }
  
  

  
    if (Motor_start == 1)
   {
     
	 PORTB = 0x04;
	 
   }
	else
   {
	 PORTB = 0x00;
	 Motor_wait_start = 0;
	 
   }
   
  
  
}