1

Тема: Atmega8 timer

TIMER 1
4 MHz

bool led_stat    = true;

void setup() {
    pinMode(13, OUTPUT);
  digitalWrite(13, LOW); 
  cli();
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
// (4000000/((15624+1)x256))=1 Hz
  OCR1A = 15624;
  TCCR1B |= (1 << WGM12);
// Prescaler 256
  TCCR1B |= (1 << CS12);
  TIMSK |= (1 << OCIE1A);
  sei();
}

void loop(){}

ISR(TIMER1_COMPA_vect){
  digitalWrite(13, led_stat); 
       led_stat = !led_stat;
  }

2

Re: Atmega8 timer

TIMER 2

bool led_stat    = true;
void setup() {
    pinMode(13, OUTPUT);
  digitalWrite(13, LOW); 
  cli();
  TCCR2 = 0;
  TCCR2 = 0;
  TCNT2 = 0;
// (4000000/((124+1)x32))=1000 Hz
  OCR2 = 124;
// Prescaler 32  
  TCCR2 |= (1 << WGM21)|(1 << CS21)|(1 << CS20);
  TIMSK |= (1 << OCIE2);
  sei();
}

void loop(){}

ISR(TIMER2_COMP_vect){
  digitalWrite(13, led_stat); 
       led_stat = !led_stat;
  }