- Get link
- X
- Other Apps
Blinking LED Automatic ON and OFF
Program
//Red LED Blinking
#include<msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
while(1)
{
volatile unsigned long i; // Volatile to prevent//optimization
P1OUT ^= 0x01; // Toggle P1.0 using XOR (i.e. Turn ON the RED LED)
i = 50000; // SW Delay
do i--;
while(i != 0);
}
}
//Green LED Blinking
#include<msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x40; // Set P1.6 to output direction
while(1)
{
volatile unsigned long i; // Volatile to prevent//optimization
P1OUT ^= 0x40; // Toggle P1.6 using XOR (i.e. Turn ON the GREEN LED)
i = 25000; // SW Delay
do i--;
while(i != 0);
}
}
//Together
#include<msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x41; // Set P1.0 & P1.6 to output direction
while(1)
{
volatile unsigned long i; // Volatile to prevent//optimization
P1OUT ^= 0x41; // Toggle P1.0 & P1.6 using XOR (i.e. Turn ON the RED & GREEN LED)
i = 50000; // SW Delay
do i--;
while(i != 0);
}
}
//Alternately
#include<msp430g2553.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
P1DIR |= 0x40; // Set P1.6 to output direction
while(1)
{
volatile unsigned long i,j; // Volatile to prevent//optimization
P1OUT = 0x01; //Turn ON the RED LED
i = 50000; // SW Delay
do i--;
while(i != 0);
P1OUT = 0x40; //Turn ON the GREEN LED
j = 50000;
do j--;
while(j != 0);
}
}
Comments
Post a Comment