Good day to all,
please i need your guide on how to solve this problem.i want to use a value return by a function call to execute the codes below after the interrupt triggers:
Code:
ISR(PORTF_INT0_vect)
{
_delay_ms(1000);
UserChoice = eDIP240_Send_Command();//--line1
if(UserChoice==40 ||UserChoice ==41 )//line2
{
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( b );
PORTC.OUTSET = PIN4_bm;
_delay_ms(500);
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( a );
PORTC.OUTSET = PIN4_bm;
}
the condition for the interrupt is that,if PINF0 on PORTF goes LOW;the codes should be executed but i observed that the codes are only executed when lines 1 and 2 are not inluded,something like this
Code:
ISR(PORTF_INT0_vect)//these codes below were executed and worked as
expected
{
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( b );
PORTC.OUTSET = PIN4_bm;
_delay_ms(500);
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( a );
PORTC.OUTSET = PIN4_bm;
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( b );
PORTC.OUTSET = PIN4_bm;
_delay_ms(500);
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( a );
PORTC.OUTSET = PIN4_bm;
}
However,when i tried the codes with while() statement, lines 1 to 3 of the codes were executed while the remaining lines where not executed.
Code:
while (PORTF.IN & 0x01);//execute code when pin goes LOW
_delay_ms(1000);
UserChoice = eDIP240_Send_Command();//line-1
if(UserChoice==40 ||UserChoice ==41 )//line--2
{
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( b );//line--3
PORTC.OUTSET = PIN4_bm;
_delay_ms(500);
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( a );//line--4
PORTC.OUTSET = PIN4_bm;
_delay_ms(500);
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( b );//line--5
PORTC.OUTSET = PIN4_bm;
_delay_ms(500);
PORTC.OUTCLR = PIN4_bm;
spiC_wrt( a );//line--6
PORTC.OUTSET = PIN4_bm;
}
i would be glad if somebody could guide me on how to figure it out.
best regards. |