Arduino Mega Timer1 in pure C problem - doesn't work Does somebody know what can be wrong in this, where I try to set Timer1 interrupt in Arduino Mega in C code only. I'm trying CTC Mode and the purpose is LED blinking with 1[s] Period. 

I work with documentation program doesn't work completely.

 #include &lt;avr/io.h&gt;
 #include &lt;avr/interrupt.h&gt;



 void setup() 
 {
   //LED -&gt; PB7 (Digital pin 13 
     DDRB |= (1&lt;&lt;PB7); 

  //FCPU = 16MHz, Prescaler :256 | CTC
   TCCR1B |= (1&lt;&lt;CS12) | (1&lt;&lt;WGM12);
   TIMSK1 |= (1&lt;&lt;OCIE1A);  // Compare Match A interrupt allowing
     OCR1A = 62500;

    sei();
    }

  void loop() 
  {

   }

   ISR(TIMER1_COMPA_vect)
   {
     PORTB ^= (1&lt;&lt;PB7); 
    }
I work with documentation program doesn't work completely.


simple:

1) check out the datasheet;
2) identify those registers needed to get tmr1 to work;
3) set or clear, as appropriate, ALL bits that are needed. Do NOT rely on default values.
4) done.