Hello
I developed the code for turning on/off the LED and i used the interrupt but after clicking 5 times to go to ISR, it freezes up.I attaceh my and as you see i don't need to return from interrup becaus after finishing the ISR , I put my cpu in Low Power mode. Is it for over flowing stack? if yes how can i clear that ?
Thanks
Behnam
#include <msp430f2013.h>
volatile unsigned int ic;
volatile unsigned int mode;
void led(void)
{
volatile unsigned int i,j;
P1DIR |= 0xC1; // P1.0, P1.6 and P1.7 output
P1SEL |= 0xC0; // P1.6 and P1.7 TA1/2 options
CCR0 = 512-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
ic=0;
mode=0;
while(1)
{
if (mode==0)
{
ic=ic+5;
CCR1 = ic; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
i = 8000; // SW Delay
do i--;
while (i != 0);
if (ic>500)
{ mode=1;
ic=512;
P1SEL &= 0x3F;
P1OUT |= 0xc0;
j=26;
do { j--;
i = 50000; // SW Delay
do i--;
while (i != 0);}
while (j != 0);
P1DIR |= 0xC1; // P1.0, P1.6 and P1.7 output
P1SEL |= 0xC0; // P1.6 and P1.7 TA1/2 options
CCR0 = 512-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
}
}
if (mode==1)
{
ic=ic-10;
CCR1 = ic; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
i = 5000; // SW Delay
do i--;
while (i != 0);
if (ic<10)
{
mode=2;
P1SEL &= 0x3F;
P1OUT &= 0x3f;
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
}
}
}
int main(void)
{
volatile unsigned int i,j;
_EINT();
ic=0;
mode=0;
// WDTCTL = WDT_MRST_32;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0xC1; // P1.0, P1.6 and P1.7 output
P1SEL |= 0xC0; // P1.6 and P1.7 TA1/2 options
P1IE |= 0x20; // P1.5 interrupt enabled
P1IES |= 0x20; // P1.5 Hi/lo edge
P1IFG &= ~0x20; // P1.5 IFG cleared
CCR0 = 512-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
while(1)
{
if (mode==0)
{
ic=ic+5;
CCR1 = ic; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
i = 8000; // SW Delay
do i--;
while (i != 0);
if (ic>500)
{ mode=1;
ic=512;
P1SEL &= 0x3F;
P1OUT |= 0xc0;
j=26;
do { j--;
i = 50000; // SW Delay
do i--;
while (i != 0);}
while (j != 0);
P1DIR |= 0xC1; // P1.0, P1.6 and P1.7 output
P1SEL |= 0xC0; // P1.6 and P1.7 TA1/2 options
CCR0 = 512-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
}
}
if (mode==1)
{
ic=ic-10;
CCR1 = ic; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
i = 5000; // SW Delay
do i--;
while (i != 0);
if (ic<10)
{
mode=2;
P1SEL &= 0x3F;
P1OUT &= 0x3f;
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
}
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
volatile unsigned int q;
P1IFG &= ~0x20; // P1.5 IFG cleared
P1OUT ^= 0x01;
q = P1IN & 0x20;
while (q == 0)
{
q = P1IN & 0x20;
}
ic=0;
if (mode<2)
{mode=2;
P1SEL &= 0x3F;
P1OUT &= 0x3f;
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
else
{
mode=0;
_EINT();
led();
}
}