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.

msp430I2031: denouncing key

Part Number: MSP430I2031

dear sir,

i am working on msp430I2031 ic

i want to implement two button reducing key(interrupt based) bouncing issue

if have example pls help me

  • Hi Hiren,

    try the Code Composer Studio Resource Explorer for device specific Code Examples.

    This is written for FR5969 - so you might have to adjust ports. This code toggles the Port 4.6 LED1 on when Button1 on Port 4.5 is pressed and off when released.

    I have not had any bouncing issues with this. Otherwise you could set a minimum debouncing time and compare it with a timer each time your Interrupt is called.

    For further information try: www.ganssle.com/debouncing-pt2.htm

    #include <msp430.h>
    void InitializePins(void);
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT
      PM5CTL0 &= ~LOCKLPM5;
    
      InitializePins();
    
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0 w/ interrupt
      __no_operation();                         // For debugger
    }
    void InitializePins(void)
    {
        P4DIR &= 0x00;
        P4OUT &= 0x00;
        P4DIR |= (BIT5 + BIT6);         // as output
        P4OUT |=  BIT5;                 // pull-up mode
        P4REN |= BIT5;                  // pull-up enable
        P4IE |= BIT5;
        P4IES |= BIT5;
        P4IFG &= ~ BIT5;
    }
    // Timer0_A0 interrupt service routine
    #pragma vector = PORT4_VECTOR
    __interrupt void Port_4(void)
    {
        P4OUT ^= BIT6;
        P4IES ^= BIT5;          // Toggles rising + falling Edge
        P4IFG &= ~BIT5;
    }

  • Dear sir,

    Thanks you for reply.

    i want to implement 2 button logic in msp 430.

    press 1 button on short time press(200 ms) = led 1 on

    press 2 button on short time press(200 ms)= led 2 on

    press 1 and 2 button on long press = led 3 on

    this type of logic implement in msp430I2031 using gpio interrupt and also reducing debouching error.

    please provide this type of example.
  • Hi,
    Using a timer in an ISR would most certainly result in critical delays in real-time applications.
    Use an if statement on your button pin instead. Start a timer and after 200ms check if it is still pressed. Then toggle the LED.
    You might want to look into basic tutorials for toggling pins and using timers. For example:
    processors.wiki.ti.com/.../MSP430_LaunchPad_Tutorials

**Attention** This is a public forum