Code:
#include <msp430.h>
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= (BIT0+BIT6); // P1.0 (Red LED), P1.1 (Green LED)
while(1)
{
volatile unsigned long i;
P1OUT &= ~BIT6; //Green LED -> OFF
P1OUT |= BIT0; //Red LED -> ON
for(i = 0; i<10000; i++); //delay
P1OUT &= ~BIT0; //Red LED -> OFF
P1OUT |= BIT6; //Green LED -> ON
for(i = 0; i<10000; i++); //delay
}
}
The watch dog, in @MrChips (hope it's ok that I'm calling you here) tutorial, the line to stop it is WDTCTL = WDTPW + WDTHOLD;, but here it's an OR operation. EDIT: Upon writing this post, I realized that they are the same, but I will let it stay.
I understand that you can say WDTCTL = WDTPW | WDTHOLD, because you have two variables to OR together. But I don't understand P1OUT &= ~BIT0;, nor do I understand the other register operations. What is the value of P1OUT? What is it being & with? I understand ~BIT0, that just means flip bit 0, right? How does P1OUT |= BIT0 turn on the led? 0 + 0 = 1?
What confuses me even more, is that if I remove the & from the OFF part, it still works as intended
Do you guys have any exercises for getting comfortable with these operations? I'm pretty much through my beginner C book (K&R book in the mailbag), and the bitwise operations have only been mentioned, not dealt with.