Other Parts Discussed in Thread: MSP430F6638
Hello, This is my First Post to TI Community......I am a Beginner in the Field of Microcontroller and I am using MSP-TS430PZ100USB Launch Pad with MSP430F6638 Controller
I am Writing a Program that will Turn the LED ON until a Switch is Pressed.
My Problem is, I am not able to Turn the LED completely off. I mean LED Remain ON all Time and If i Press the Switch it only Increases the Intensity of LED and after I release the switch it step back to it initial condition (Dim the LED's Intensity)
I am using a Pull Up Network to Read the Switch Input
My Code is :
#include <msp430.h>
#define SW BIT1
#define LED BIT0
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop WatchDog timer
P1OUT &= ~LED; //Make LED off Initially
P1DIR |= LED; //Set Direction of LED as Output
while(1){
while((P1IN & SW) == 1); //Wait Till the Switch is Pulled Up
P1OUT |= LED; //Turn on the LED (Active High)
while((P1IN & SW) == 0); //Wait Till the Switch is Pulled Down i.e; until Switch is Pressed
P1OUT &= ~LED; // Turn off the LED
}
return 0;
}
Please help me.