This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

function call problem in interrupt routine of MSP430FR5969



Dear All,

I have two codes whose functionality is same, but I'm getting different functionality when I execute them. I'm working on MSP430 launchpad. Followings are my two codes. Please provide me proper solution to my second code.

Code 1.

#include <msp430.h>

int main(void)
{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0;

// Set P1.0 to output direction
P4DIR |= BIT6;
P1IE |= BIT1; // P1.3 interrupt enabled
P1IES |= BIT1; // P1.3 Hi/lo edge
P1REN |= BIT1; // Enable Pull Up on SW2 (P1.3)
P1IFG &= ~BIT1; // P1.3 IFG cleared
//BIT3 on Port 1 can be used as Switch2
P4IE |= BIT5;
P4IES |= BIT5;
P4REN |= BIT5;
P4IFG &= ~BIT5;
P1OUT &= ~BIT0;
P4OUT &= ~BIT6;

PM5CTL0 &= ~LOCKLPM5;
__bis_SR_register(LPM4_bits + GIE);
while(1);
}

#pragma vector=PORT1_VECTOR
__interrupt void vector(void)
{
int a;
for(a=0;a<3;a++)
{

P1OUT |= BIT0;

int i=100000;
int j=100000;
int k=100000;
while(i!=0 && j!=0 && k!=0)
{
i--;
j--;
k--;
}

P1OUT &= ~BIT0;
P4OUT |= BIT6;

int i=1000000;
int j=1000000;
int k=1000000;
while(i!=0 && j!=0 && k!=0)
{
i--;
j--;
k--;
}

P1OUT &= ~BIT0;

P4OUT &= ~BIT6;

P1IFG &= ~BIT1;

}
}

//This code works properly. I'm expecting same delay by putting all those delay functional instruction in a function. But I'm not able to get that delay. Please help me in getting delay in second code

code 2

#include <msp430.h>

int main(void)
{ void delay_byme(void);
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0;

// Set P1.0 to output direction
P4DIR |= BIT6;
P1IE |= BIT1; // P1.3 interrupt enabled
P1IES |= BIT1; // P1.3 Hi/lo edge
P1REN |= BIT1; // Enable Pull Up on SW2 (P1.3)
P1IFG &= ~BIT1; // P1.3 IFG cleared
//BIT3 on Port 1 can be used as Switch2
P4IE |= BIT5;
P4IES |= BIT5;
P4REN |= BIT5;
P4IFG &= ~BIT5;
P1OUT &= ~BIT0;
P4OUT &= ~BIT6;

PM5CTL0 &= ~LOCKLPM5;
__bis_SR_register(LPM4_bits + GIE);
while(1);
}

#pragma vector=PORT1_VECTOR
__interrupt void vector(void)
{
//void delay_byme(void);
int a;
for(a=0;a<3;a++)
{

P1OUT |= BIT0;

delay_byme();


P1OUT &= ~BIT0;
P4OUT |= BIT6;
delay_byme();

P1OUT &= ~BIT0;

P4OUT &= ~BIT6;

P1IFG &= ~BIT1;

}
}

void delay_byme(void)
{
int q=100000;
int w=100000;
int e=100000;
while(q!=0 && w!=0 && e!=0)
{
q--;
w--;
e--;
}
}

**Attention** This is a public forum