Jump to content


  • Content Count

  • Joined

  • Last visited

About just_another_noob

  • Rank
    Noob Class
  1. Thanks everyone for the great responses. jsolarski - That is just about what my thought process was on the matter. It was good to have confirmation that I was thinking along a working path. I managed to get the code to work. I tried the different suggestions posted. Using (P1IES & BIT3) != 0 always returned as true and using P1ES just threw errors. I am guessing it is because I missed something and that these techniques would work with more nimble fingers at the keyboard. My solution was to create a variable to indicate when the button was pressed, and a variable to indicate when the timer was set. I'll include the code below. I invite you all to make suggestions on how to make the code leaner, more efficient, etc. My goal is to learn how to make this code efficient, so that I can store it a a bag of tricks for when I start doing things that are more complex. For now however, I am just trying to learn how all of this works. #include #define LED_RED BIT0 #define LED_GR BIT6 #define BUTTON BIT3 int pressed = 0;// declare variable to indicate button press int myTimer = 0;// declare variable to indicate timer running int main(void) { WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer P1DIR |= (LED_RED + LED_GR);// Set P1.0 to output direction P1OUT &= ~(LED_RED + LED_GR);// set P1.0 to 0 (LEDs 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) { if (pressed == 0)// If the button hasn't been pressed yet { TACTL = TASSEL0 + ID_3 + TACLR;// TACLK, divider 8, clear TAR, TACCTL0 = CCIE;// enable interrupt TACCR0 = 4000;// set timer for 3 seconds TACTL |= MC_1;// setting mode bits starts timer up mode myTimer = 1;// set this to 1 to indicate the timer has started pressed = 1;// set this to 1 to indicate the button has been pressed } // end If pressed else if ((pressed == 1))//If the button has been pressed { pressed = 0;// reset button press variable if (myTimer == 1)// If the timer is going, this means that 3 sec hasn't elapsed or this is a button release { P1OUT ^= (LED_GR);// P1.0 = toggle TACCTL0 ^= CCIE;// turn off timer interupt TACTL = MC_0 + TACLR;// stop timer and clear timer myTimer = 0; } } P1IFG &= ~BUTTON;// P1.3 IFG cleared P1IES ^= BUTTON;// toggle the interrupt edge, // This means that an interrupt will be triggered // on p1.3 button up as well as button press } //end PORT1_VECTOR // Timer interrupt #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A0(void) { TACCTL0 ^= CCIE;// enable interrupt TACTL = MC_0 + TACLR;// stop timer and clear timer P1OUT ^= (LED_RED);// P1.0 = toggle P1IFG &= ~BUTTON;// P1.3 IFG cleared myTimer = 0; // set my timer to 0 since the time (3 sec) has elapsed } //end TIMERA0_VECTOR
  2. Thanks gordon! I think that is what I am looking for, I'll give that a try and see how it works. I am basically trying to have one LED light if the button has been held for a certain period (3 sec) and the other to be lit if the button has been released before that time. Kind of like the mode button common to digital watches; if you press the button it shows the date, but if you hold the button, it allows you to edit the time. j.a.n.
  3. Hello All, I have been playing with my new launch pad trying to figure things out. I am currently attempting to use a single button for multiple purposes. For instance, if the button is held for 3 sec the red led is lit, but if the button is pressed and released before 3 sec, the green one is lit. I thought that this would be a simple exercise, but I haven't been able to quite get it to work. I know that I can toggle the interrupt edge using P1IES ^= BUTTON (Where BUTTON = BIT3), but what I don't know is how to determine if the edge is high or low. I have been looking through code and searching on line, but I must have missed it somewhere. If anyone has any ideas (hey, I'll even take leads if you think I ought to "work for it" more) . Thanks j.a.n.
  4. I recently received my launchpad in the mail, and wanted to say hello to everyone.
  • Create New...