hi i am just toggoling a paticular pin in port a i am not able to get expected result. i have included the code below please take a look
#include "derivative.h"
void delay(void);
{
EnableInterrupts;
PTADD_PTADD0 = 1;
PTDPE_PTDPE0 = 0;
{
PTAD_PTAD0 = 1;
delay();
PTAD_PTAD0 = 0;
delay();
PTAD_PTAD0 = 1;
delay();
PTAD_PTAD0 = 0;
delay();
__Reset_Watchdog;
}
}
{
int i, j;
for (i=0; i<200; i++)
for(j=0; j<200; j++);
}
The problem that i am facing is that when i run in debug mode setp by setp execution the program counter in not going according to the written program it is getting currupted and the other thing that i noticed is that when last four lines of the code in while loop, except for" __resetwatch dog" is taken out then the code and the debugger works ablsolutely fine but as soon as i include another toggle in the code the problem starts.
Thanks
Solved! Go to Solution.
hello Vikas,
the problem is due to optimization. the simple way to avoid optimization is to add "asm nop;"
while (1)
{
PTAD_PTAD0 = 1;
asm nop;
delay();
PTAD_PTAD0 = 0;
asm nop;
delay();
PTAD_PTAD0 = 1;
asm nop;
delay();
PTAD_PTAD0 = 0;
asm nop;
delay();
__Reset_Watchdog;
}
==============================================
this answer is for you. if it helps, please click on "correct answer" button. thanks!
Best Regards,
Zhang Jun
hi vikas,
you mentioned "program it is getting currupted ". can you please send me a screenshot of it?
Best Regards,
Zhang Jun
hello Vikas,
the problem is due to optimization. the simple way to avoid optimization is to add "asm nop;"
while (1)
{
PTAD_PTAD0 = 1;
asm nop;
delay();
PTAD_PTAD0 = 0;
asm nop;
delay();
PTAD_PTAD0 = 1;
asm nop;
delay();
PTAD_PTAD0 = 0;
asm nop;
delay();
__Reset_Watchdog;
}
==============================================
this answer is for you. if it helps, please click on "correct answer" button. thanks!
Best Regards,
Zhang Jun
Hi Jennie,
Thanks a lot for the reply it did work by inserting above line.