boolean myflag1 = true;
void setup() {
DDRB = 0xFF; // Set PORTB as outputs
TCCR1A = 0; // initialize timer1
TCCR1B = 0; // clear all bit
OCR1A = 10416; // target at 1 Hz
TIMSK1 = 0; // disable all interrupts
TCNT1 = 0x0; // Reset Counter
TIFR1 = 0x6 ; // Clear all interrupt flags
TCCR1B |= (1 << WGM12); // set to CTC mode (Have a look at Table 2-2)
TCCR1B |= (1 << CS12); // prescaler 256 (Have a look at Table 2-1)
}
void loop() {
if(TIFR1 & (1 <<OCF1A)){ // check match interrupt
TIFR1 = (1 << OCF1A); // clear match interrupt
if(myflag1){
PORTB &= ~(1 <<PORTB7); // turn off PB7
}
else{
PORTB = (1 <<PORTB7); // turn on PB7
}
myflag1 =! myflag1; // toggle flag
}
}