I am writing a simple program that has to blink LEDs with frequency 1Hz using Timer0 and Timer1 without using delay() function.
The program gets complicated, but it doesn't blink. What can I do to make it work?
Below are additional details:
Michrochip studio
F_CPU 16000000UL
Timer0 set on 256.
Timer 1 starts counting from 3036.
The LED is connected to the PB1 PIN.\
#include <avr/io.h>
#include <avr/interrupt.h>
void initTimer0() {
TCCR0B |= (1 << CS02);
TIMSK |= (1 << TOIE0);
}
void initTimer1() {
TCNT1 = 3036;
TIMSK |= (1 << TOIE1);
}
ISR(TIMER0_OVF_vect) {
PORTB ^= (1 << DDRB);
}
ISR(TIMER1_OVF_vect) {
TCNT1 = 3036;
}
int main(void) {
//DDRB |= (1 << DDB1);
initTimer0();
initTimer1();
sei();
while (1) {
if (TCNT1 >= 65536) {
DDB1 = ~DDB1;
TCNT1 = 3036;
}
}
return 0;
}