#include <Arduino.h>
void setupTimer0(){
noInterrupts();
TCCR0A = 0;
TCCR0B = 0;
TCNT0 = 0;
// 16 MHz / (prescale+1)*1024
OCR0A = 124;
TCCR0B |= (1 << WGM02);
TCCR0B |= (1 << CS02) | (1 << CS00);
TIMSK0 |= (1 << OCIE0A);
interrupts();
}
void setupTimer1(){
noInterrupts();
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
// 16 MHz / (prescale+1)*1024
OCR1A = 7812;
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12) | (1 << CS10);
TIMSK1 |= (1 << OCIE1A);
interrupts();
}
void setup() {
DDRC = 0xFF;
setupTimer0();
setupTimer1();
}
void loop() {
PORTC = (1<<PC4) | (1<<PC5) |(1<<PC6) |(1<<PC7);
delay(2000);
PORTC = (0<<PC4) | (0<<PC5) |(0<<PC6) |(0<<PC7);
delay(2000);
}
ISR(TIMER0_COMPA_vect){
PORTC ^= (1<<PC2) |(1<<PC3);
}
ISR(TIMER1_COMPA_vect){
PORTC ^= (1<<PC0) |(1<<PC1);
}