Okay, here's an easy one!
I wrote a program that whenever my launchpad gets its P1.3 button pressed, the leds flash - red, then green, 20 times..
For the sake of simplicity I wrote separate functions of lighting red led, and for lighting the green led..
VERSION #1: P1.3 isn't registering button presses after being pressed just once
|
#include <msp430.h> inline void blinkRedLED()
WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_1MHZ; __enable_interrupt(); P1OUT |= BIT3; #pragma vector=PORT1_VECTOR unsigned char tick=0; for(i=20;i>1;i--) if (tick==0) stopAllLEDS(); return; |
For my great amusment, it worked, but just once - means if the lanuchpad senses I pressed P1.3, the leds will flash, it will exit the interrupt and will put the launchpad back to "sleep" so I suppose.. If the P1.3 then pressed again the launchpad wouldn't do anything (unless, ofcourse, it is restarted via the restart button).
I suppose that I should "restart" the button somehow inside the __interrupt... what do you think?
Another thing I noticed, when I make a little change in the main function - if I remove WDTCTL = WDTPW + WDTHOLD; the P1.3 works great (after function is done, if button is pressed again, the __interrupt is called) - but another problem arises: I used __delay_cycles(100000); when lighting the leds, now without this line - only my red led (P1.0) lights, the green isn't flashing at all...
VERSION #2: P1.3 is registering button presses after being pressed just once - but __delay_cycles(....) function isn't working well - so now leds aren't lighting properly..
| #include <msp430.h>
#include "msp430g2553.h" inline void blinkRedLED()
//WDTCTL = WDTPW + WDTHOLD; //difference is here! BCSCTL1 = CALBC1_1MHZ; __enable_interrupt(); P1OUT |= BIT3; #pragma vector=PORT1_VECTOR unsigned char tick=0; for(i=20;i>1;i--) if (tick==0) stopAllLEDS(); return; |
How can I make the launchpad "catch" all the button presses AND flash the leds properly :-)
Thanks a bunch!!