This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

about when i press the button (holding stage) that 2 sec after that led will glow using msp430g2553

Other Parts Discussed in Thread: MSP430G2553

hello sir,

i had to try to form a 2 sec timer counter interrupt  , but it wont work . it only happen 2 sec delay . but i need to when i hold the button at the time timer will count 2 sec and then led will blink . that code i will attached here. please give need full solution.

#include <msp430g2553.h>




void main(void)
    {
    WDTCTL = WDTPW|WDTHOLD;

    P1OUT &= 0x00;
    P1DIR &= 0x00;

    P1DIR |= BIT6;
    P1REN |= BIT3;
    P1OUT |= BIT3;

    P1IE |= BIT3;
    P1IFG &= ~BIT3;
    P1IES |= BIT3;


    TACTL |= TASSEL_1;
    TACTL |= MC_0;

    _BIS_SR( GIE );

    while(1)
    {}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
    unsigned char in_prt;
    P1IFG &= ~BIT3;
    P1IES ^= BIT3;

    in_prt = P1IN & BIT3;

    if(in_prt > 0)
    {
      TACCR0 = 24000;
      TACTL |= TASSEL_1;
      TACTL ^= MC_3;
      TACCTL0 |= CM_1;
      TACCTL0 |= CCIE;
    }
    else
    {
      TACTL &= ~MC_1;
      //TACCTL0 &= ~CCIE;
    }
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void timer_A0(void)
{
    P1OUT ^= BIT6;
    TACTL &= ~MC_1;
    TACCTL0 &= ~CCIE;
}

  • In your code, you start the timer. Maybe multiple times due to button bouncing, but that shouldn’t be a problem here.

    When the timer expires, you stop the timer. That is a just delay. To have the LED blinking rather than just toggling state once after the delay, you need to have continuous timer interrupts with changed frequency (twice the desired blinking frequency). You may check in the timer ISR whether the button is still pressed.

    You can omit the port pin ISR totally, if you set-up the timer for your blinking frequency.
    Keep a global counter. In the timer ISR check the port pin. If the button is pressed, start incrementing the counter, if not, clear it and switch the LED off. If the counter reaches a certain value (your 2s delay), stop incrementing it and toggle the LED instead. Once you release the button, the counter is reset, the LED deactivated and stops blinking and it is waiting for the next button press, at which the 2s delay will start again before the LED begins blinking..

  • Thank you for your valuable solution for me....

**Attention** This is a public forum