- Get link
- X
- Other Apps
Blinking LED through Push button
Blinking LED through Switch
Program
#include <msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR|= BIT0 + BIT6; //configure Port1 pin0(Red_Led) and pin6(Green_Led) as Outputs
P1DIR&=~BIT3; //configure Port1 pin3 as Input
P1REN|=BIT3;
P1OUT|=BIT3;
P1OUT&= ~(BIT0+BIT6); //Clear any output voltage at pin0(Red_Led) and pin6(Green_Led)
while(1)
{
if(P1IN&BIT3) //Check if button is pressed, will return false on button press
{
P1OUT&= ~(BIT0+BIT6); //Turn OFF the LEDs
}
else
{
P1OUT|=BIT0+BIT6; //Turn ON the LEDs
}
}
}
#include <msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR|= BIT0 + BIT6; //configure Port1 pin0(Red_Led) and pin6(Green_Led) as Outputs
P1DIR&=~BIT3; //configure Port1 pin3 as Input
P1REN|=BIT3;
P1OUT|=BIT3;
P1OUT&= ~(BIT0+BIT6); //Clear any output voltage at pin0(Red_Led) and pin6(Green_Led)
while(1)
{
if(P1IN&BIT3) //Check if button is pressed, will return false on button press
{
P1OUT|=BIT0+BIT6; //Turn ON the LEDs
}
else
{
P1OUT&= ~(BIT0+BIT6); //Turn OFF the LEDs
}
}
}
#include <msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR|= BIT0 + BIT6; //configure Port1 pin0(Red_Led) and pin6(Green_Led) as Outputs
P1DIR&=~BIT3; //configure Port1 pin3 as Input
P1REN|=BIT3;
P1OUT|=BIT3;
P1OUT&= ~(BIT0+BIT6); //Clear any output voltage at pin0(Red_Led) and pin6(Green_Led)
while(1)
{
if(P1IN&BIT3) //Check if button is pressed, will return false on button press
{
P1OUT|=BIT0; //Turn ON the RED LED
P1OUT&= ~BIT6; //Turn OFF the GREEN LED
}
else
{
P1OUT|=BIT6; //Turn ON the GREEN LED
P1OUT&= ~BIT0; //Turn OFF the RED LED
}
}
}
#include <msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR|= BIT0 + BIT6; //configure Port1 pin0(Red_Led) and pin6(Green_Led) as Outputs
P1DIR&=~BIT3; //configure Port1 pin3 as Input
P1REN|=BIT3;
P1OUT|=BIT3;
P1OUT&= ~(BIT0+BIT6); //Clear any output voltage at pin0(Red_Led) and pin6(Green_Led)
while(1)
{
if(P1IN&BIT3) //Check if button is pressed, will return false on button press
{
P1OUT|=BIT6; //Turn ON the GREEN LED
P1OUT&= ~BIT0; //Turn OFF the RED LED
}
else
{
P1OUT|=BIT0; //Turn ON the RED LED
P1OUT&= ~BIT6; //Turn OFF the GREEN LED
}
}
}
Comments
Post a Comment