Hello, after i checked that empty while() loops have a undesired effect to my program, i decided to write the simple below program:
//just before main():
stop = 0;
while(stop ==0){
}
//external interrupt: (when i activate it, the var stop changes)
ISR(INT0_vect){
stop =1;
}
The above program, will never leave while(stop == 0), no matter how many times i activate the interrupt. The solution was to add a _delay_ms() inside while():
//just before main():
stop = 0;
while(stop ==0){
_delay_ms(10);
}
//external interrupt:
ISR(INT0_vect){
stop =1;
}
Now, it worked fine, and passed the while() loop. I have come across this 'issue' many times before, and i always solved it using delay(). But not i think its the moment of truth. What is going on? Why do i need the delay(), or a -kind of- big code inside while() to make it work?
My guess is, the compiler optimizes the code... If that is the case, how can i avoid code optimization, or, what is a way around?
thanks