Hello programmers. Please help.
What microcontroller/compiler do, when he see a "bit" which was already set before. Is it bad programming style? Will a "bit" be overwritten again?
In the "else" we see as a " PB2 bit" could be rewritten to zero. Or maybe I should not think about it at all? The compiler does all the work for me. I guess I should learn assembler to solve similar questions by myself in the future, but may be somebody could explain. Thanks.
#include <avr/io.h> #define BUTTON_PRESSED (PINB & (1<<PB1)) #define LED_ON PORTB |= (1<<PB2) #define LED_OFF PORTB &= ~(1<<PB2) void setup () { DDRB = 0b00011101; PORTB = 0b00100010; } int main(void) { setup(); while(1) { if (!BUTTON_PRESSED) { LED_ON; } else { LED_OFF; // this place will executed again and again, while button not pressed. } } }