Hi everyone. I'm new to MSP430 and microcontrollers. And right now I'm trying to write a program that changes the LED's state (OFF-ON-BLINK) by every press on P1.1 button. I have used "switch-case" statement to achieve this and to control the switch statement's variable, I used a port interrupt. And for the blinking operation, I used a timer interrupt. Everything works as it should be. But there is a problem with the blink case.
The program starts with LED off. Then I press the button and LED turns on. Another press on the button and the LED starts to blink. After the blink case, when the button is pressed one more time, the program must return to the initial state, which turns the LED off. And one more press turns the LED on, one more starts to blink and so on.
But when the LED starts to blink, the program stuck at the infinite loop point where the timer get involved to toggle the LED state and a pressing button has no effect, the LED continues to blink.
Without the interrupts, (by usign polling etc.) my code works flawlessly. So in order to not overcrowd here, I won't post my code completely.
volatile unsigned int mode; #pragma vector = timer_vector_here __interrupt void someNameHere (void) { P1OUT ^= BIT0; TA0CTL &= ~TAIFG; } #pragma vector = port_vector_here __interrupt void anotherNameHere (void) { mode++; P1IFG &= ~BIT1; } int main(void) { /* Port settings, P1.0 to output, P1.1 to input etc. * Port Interrupt settings, IES, IRQ etc. * Timer settings, TA0CTL, SMCLK clock etc.*/ __enable_interrupt(); mode = 0; while (1) { if (mode > 2) { mode = 0; } switch (mode) { case 0: P1OUT &= ~BIT0; break; case 1: P1OUT |= BIT0; break; case 2: TA0CTL = TASSEL_2 + MC_1 + TACLR + TAIE; TA0CCR0 = 50000; TA0CTL &= ~TAIFG; for(;;); break; } } }
What I wrote on the other parts is not important. What important thing is, what written in the case 2 and timer ISR. So to sum up, my question is, how can I exit that timer interrupt when I press the button to turn the LED off and continue to program?
P.S. I didn't use and not want to use LPM or something. So please don't give me examples that includes LPM. Thank you so much in advance