title: How to make Atmega328 timmer interrupt tick every 1 second?
body: <p>I've an Atmega328p and I've connected an LED to it's D4 pin and I want it to turn LED on/off every one second.</p>
  <p>I found <a href="https://sites.google.com/site/qeewiki/books/avr-guide/timers-on-the-atmega328" rel="nofollow noreferrer">this tutorial</a> and I've change it base on some online AVR timmer calculator and the 12MHZ external crystal which I've used, to this :</p>
  <pre><code>#define F_CPU 12000000UL
  #include &lt;avr/io.h&gt;
  #include &lt;avr/interrupt.h&gt;
  
  
  int main(void)
  {
  
      DDRD |= 1 &lt;&lt; 4;
      PORTD |= 1 &lt;&lt; 4;
  
      ICR1 = 0xB71B;
  
      TCCR1B |= (1 &lt;&lt; WGM12);
      // Mode 4, CTC on OCR1A
  
      TIMSK1 |= (1 &lt;&lt; ICIE1);
      //Set interrupt on compare match
  
      TCCR1B |= (1 &lt;&lt; CS12);
      // set prescaler to 256 and starts the timer
  
  
      sei();
      // enable interrupts
  
  
      while (1)
      {
          // we have a working Timer
      }
  }
  
  ISR (TIMER1_COMPA_vect)
  {
      PORTD |= 0 &lt;&lt; 4;
      // action to be done every 200ms
  }
  </code></pre>
  <p>The LED is always on or off no mater how I change ICR1 value. How can I make it work?</p>