Hello,
My aim is if I press a push button P1.3 then LED (P1.0) should off/on otherwise LED (P1.6) should blink.
In Below code, LED (P1.0) is on/off when i press button and LED (P1.6) glows once. LED (P1.6) glows once and wait for the user to press the button. My task is the the code should blink the LED (P1.6) continuously if user doesn't press the button. If the user press the button then LED (P1.0) should glow and then LED (P1.6) should blink until user press the push button. Please tell me how can i do this.
#include <msp430g2553.h>
#define LED0 BIT0
#define LED1 BIT6
#define BUTTON BIT3
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= (LED0 + LED1); // Set P1.0 to output direction
// P1.3 must stay at input
P1OUT &= ~(LED0 + LED1); // set P1.0 to 0 (LED OFF)
P1IE |= BUTTON; // P1.3 interrupt enabled
P1IFG &= ~BUTTON; // P1.3 IFG cleared
__enable_interrupt(); // enable all interrupts
while(1)
{
P1OUT ^= LED1;
__bis_SR_register(LPM4_bits + GIE);
}
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1OUT ^= BIT0;
P1IFG = 0; // clear interrupt
__bic_SR_register_on_exit(LPM4_bits);
}
Thanks.