Zählwerk

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

// LED-Anzeige
#define STL0 PD5
#define STL1 PD6



#define SEG1 (1<<PB2)
#define SEG2 (1<<PB3)
#define SEG3 (1<<PB1)
#define SEG4 (1<<PB4)
#define SEG5 (1<<PB7)
#define SEG6 (1<<PB6)
#define SEG7 (1<<PB5)


#define A0 (SEG1 | SEG2 | SEG3 | SEG5 | SEG6 | SEG7)
#define A1 (SEG3 | SEG7 )
#define A2 (SEG1 | SEG3 | SEG4 | SEG5 | SEG6)
#define A3 (SEG1 | SEG3 | SEG4 | SEG6 | SEG7)
#define A4 (SEG2 | SEG3 | SEG4 | SEG7)
#define A5 (SEG1 | SEG2 | SEG4 | SEG6 | SEG7)
#define A6 (SEG1 | SEG2 | SEG4 | SEG5 | SEG6 | SEG7)
#define A7 (SEG1 | SEG3 | SEG7)
#define A8 (SEG1 | SEG2 | SEG3 | SEG4 | SEG5 | SEG6 | SEG7)
#define A9 (SEG1 | SEG2 | SEG3 | SEG4 | SEG6 | SEG7)

//EEPROM

#define EEPROM  __attribute__ ((section (".eeprom")))

//Taster

#define Taster(port,pin,taster,operation,time_P)       \
({                                     			\
												\
	   if ( taster == 0) 						\
	   {										\
			     								\
		   if ( port & (1<< pin )) 				\
	       { 									\
												\
			 						            \
		     taster = 1;						\
			 time_P = 0;						\
		   }									\
	   }										\
	                                            \
	   if ( taster == 1)                        \
       { 										\
			if (time_P == 50)			        \
		   {                                    \
			    if ( port & (1<< pin ))         \
               {                                \
                                                \
                 taster = 2;                    \
                 operation ;                    \
				 eeprom_write_byte (&save, zahl);\
               }                                \
                else                            \
			   {                                \
                                                \
                  taster = 0;                   \
	           }                                \
												\
           }									\
	   }                                        \
												\
												\
												\
	   if ( taster == 2)						\
	   {										\
           if (!( port & (1<< pin )))		    \
	       {								    \
		     taster = 0;					    \
                                                \
		   }                                    \
	   }                                        \
})                                           

 




// Variablen

const char ziffer[11] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, 0};
unsigned char volatile zahl;
unsigned char volatile stelle;
unsigned char volatile stelle_P;
unsigned char volatile time_Pa;
unsigned char volatile time_Pb;
unsigned char s;
unsigned char volatile tastera;
unsigned char volatile tasterb;
unsigned char volatile tasterc;
uint8_t save EEPROM = 12;


//Hauptschleife

int main(void)
{       
  TCCR0B = 0x03;
  TIMSK |= (1 << TOIE0);
  sei();
  
  zahl = eeprom_read_byte (&save);
  
  DDRB = 0xff;
  DDRD = 0x60;
    
   while(1)
   {
     
     
	   Taster(PIND,PIND1,tastera,zahl++,time_Pa);
	   Taster(PIND,PIND0,tasterb,zahl = 0,time_Pb);
       
     
     
     
	  
	   if (stelle_P == 5)
	   {
	     
		 stelle_P = 0;
		 stelle++;
		 
		 
		    if (zahl == 100) 
            {
	         zahl = 0;
			}
			
		 
		    if (stelle == 2) 
            {
	         stelle = 0;
			}
			
	   }
      
        
       switch (stelle)
	   {
		 case 0:
		  PORTD &= ~(1 << STL0);
		  s = zahl / 10;
		  PORTB = ziffer[s];
		  PORTD |= (1 << STL1);
		 break;
		    
		 case 1:
		  PORTD &= ~(1 << STL1);
		  s = (zahl % 10);
		  PORTB = ziffer[s];
	      PORTD |= (1 << STL0);
		 break;
		 
	   }   
   }  
}

// Timer Überlauf

SIGNAL (SIG_OVERFLOW0)
{

  TCNT0 = 250;	
    
  stelle_P++;
  time_Pa++;
  time_Pb++;
  
}