//*************************************************************************************** // MSP430 PushButton that toggles LED at P1.0 On and OFF // // Description; PushButton in P1.3 through interrupt turns on and off the LED in P1.0
// By changing the P1.3 interrupt edge, the interrupt is called every time the button
// is pushed and pulled; toggling the LED everytime. // ACLK = n/a, MCLK = SMCLK = default DCO // // MSP430x2xx // ----------------- // /|| XIN|- // | | | // --|RST XOUT|- // | | // | P1.0|-->LED // // Aldo Briano // Texas Instruments, Inc // June 2010 // Built with Code Composer Studio v4 //*************************************************************************************** #include
#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 for(;;) {} }
// Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1OUT = 0x40; // green light __delay_cycles(1000000); // delay 3 seconds
P1OUT = 0x00; //red light __delay_cycles(100000); // delay 3 seconds
P1OUT = 0x01; //red light __delay_cycles(1000000000); // delay 3 seconds P1IFG &= BUTTON; // P1.3 IFG cleared P1IES ^= BUTTON; // toggle the interrupt edge, // the interrupt vector will be called // when P1.3 goes from HitoLow as well as // LowtoHigh }
OK, I tried again with this program but even if I stop pushin the button, the two LED switch on even if normally, they should stop.
Can someone help me because I do not know where is the problem. I have take a look to this link to understand how is working the push button :
formatting link
but apparently, with this sequence, it does not stop.
Thanks for your advices.
--------------------------------------- Posted through
formatting link