not able to toggle a paticlar pin on the MC90S08DN16

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

not able to toggle a paticlar pin on the MC90S08DN16

跳至解决方案
1,000 次查看
vikassubramani
Contributor II

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 <hidef.h>

 

#include "derivative.h"

void delay(void);

 

 

void main(void)

 

{

EnableInterrupts;

        PTADD_PTADD0 = 1;

PTDPE_PTDPE0 = 0;

 

         while (1)

 

{

PTAD_PTAD0 = 1;

delay();

PTAD_PTAD0 = 0;

delay();

PTAD_PTAD0 = 1;

delay();

PTAD_PTAD0 = 0;

delay();

                __Reset_Watchdog;

          }

}

 

 

void delay(void)

 

{

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

标签 (1)
0 项奖励
1 解答
764 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

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

在原帖中查看解决方案

0 项奖励
6 回复数
764 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

hi vikas,

you mentioned "program it is getting currupted ".  can you please send me a screenshot of it?

Best Regards,

Zhang Jun

0 项奖励
764 次查看
vikassubramani
Contributor II

image1.png

0 项奖励
764 次查看
vikassubramani
Contributor II

image2.png

0 项奖励
764 次查看
vikassubramani
Contributor II

image3.png

0 项奖励
765 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

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

0 项奖励
764 次查看
vikassubramani
Contributor II

Hi Jennie,

               Thanks a lot for the reply it did work by inserting above line.

0 项奖励