It is strange and rare. I am trying to blink a LED at PD0 at 2hz, but it doesn't work. Seems to me that while loop doesn't work at all. I have triple checked the code. what is the problem here?
uint8_t c=0;
int main(void){
DDRD= 1<<0 ;
TCCR0 = (1 << CS02) | (1 << CS00); // (clk_i/o )/1024 ( Prescaler)
TIMSK |= 1<< TOIE0;
sei();
while (1){
if ( c >=30 ) { PORTD ^= 1<<0; c=0; } //61.035/30= 2.034 hz
}
}
ISR (TIMER0_OVF_vect){
c++; //16000000/1024/256=61.035 hz
}
Of course, I know the solution. It's by adding a random line of code to the while loop, and it works again. Strange!! What would be the problem? compiler bug??
uint8_t c=0;
int main(void){
DDRD= 1<<0 ;
TCCR0 = (1 << CS02) | (1 << CS00); // (clk_i/o )/1024 ( Prescaler)
TIMSK |= 1<< TOIE0;
sei();
while (1){
if ( c >=30 ) { PORTD ^= 1<<0; c=0; } //61.035/30= 2.034 hz
_NOP();
}
}
ISR (TIMER0_OVF_vect){
c++; //16000000/1024/256=61.035 hz
}