title: Implementing timer code for Atmega8 into Atmega16
body: <p>This code snippet is written for Atmega8 taken from <a href="http://www.electronics-lab.com/projects/mcu/020/index.html" rel="nofollow noreferrer">clapper circuit using Atmega8</a>. Can anyone convert this code snippet for Atmega16 with a little explanation. As I am trying to implement the same for Atmega16 and having some trouble with the timer part.</p>
  
  <pre><code>#define BURST_TIME  70
  #define READY_TIME  150
  #define TIME_OUT    300
  
  void timer_init()
  {
      TIFR |= (1&lt;&lt;TOV0);      
      //set interrupt on overflow
      TIMSK |= (1&lt;&lt;TOIE0);
      TCNT0 = 223;
  }
  
  ISR (TIMER0_OVF_vect)
  {       
      TCNT0 = 223;
      timer++;
  
      if (timer == BURST_TIME)
      {
          burst = 1;
          ready = 0;
      } else if (timer == READY_TIME)
      {
          burst = 0;
          ready = 1;
      } else if (timer == TIME_OUT)
      {
          timer = 0;
          burst = 0;
          ready = 0;
          first = 0;
          stop_timer();
      }
  }
  
  void start_timer()
  {
      TCCR0 |= (1&lt;&lt;CS02);
  }
  
  void stop_timer()
  {
      TCCR0 &amp;= ~(1&lt;&lt;CS02);
  }
  </code></pre>