Hi every body i am a new bie to MC9S08DN16 controller and i am facing problem in toggling the port the code is as below.
/* [sample program to toggle the port D of the micro controller ] */
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
void port_initialize(void);
void delay(void);
void main(void)
{
EnableInterrupts;
/* include your code here */
port_initialize();
while(1)
{
PTED = 0x00; /* flashing 0's on to port D */
delay(); /* delay function */
PTED = 0xff; /* flashing 1's on to port D */
delay(); /* delay function */
}
/* loop forever */
/* please make sure that you never leave main */
}
void port_initialize(void )
{
PTEDD = 0xff; /* port D data direction register configured as output */
PTEPE = 0x00; /* Internal pull-up/pull-down device disabled for port D */
PTESE = 0x00; /* Output slew rate control disabled for port D */
// PTEPE = 0x00; /* Port disabled as interrupt */
}
void delay()
{
unsigned int i,j;
for(i=0; i<255; i++)
for(j=0; j<255;j++);
}
The problem i am facing is that although the code is in infinate loop. when i run the program after few seconds the code will exit unexpectedly and will lead to a new window and displays the following.
#pragma NO_EXIT
__EXTERN_C void _Startup(void) {
/* set the reset vector to _Startup in the linker parameter file (*.prm):
'VECTOR 0 _Startup'
purpose: 1) initialize the stack
2) initialize run-time, ...
initialize the RAM, copy down init data, etc (Init)
3) call main;
called from: _PRESTART-code generated by the Linker
*/
INIT_SP_FROM_STARTUP_DESC(); /*lint !e960 MISRA 14.3 REQ, not a null statement (instead: several HLI statements) */
#ifndef __ONLY_INIT_SP
Init(); /*lint !e522 function 'Init' contains inline assembly */
#endif
#ifndef __BANKED__
__asm JMP main; /* with a C style main(); we would push the return address on the stack wasting 2 RAM bytes */
#else
__asm CALL main;
#endif
}
Solved! Go to Solution.
hi Vikas,
from your description, your program got reset when running in loop.
I wonder the reset was caused by COP. please try to add feed dog code inside for() loop:
for example:;
for(;;) {
... ...
__RESET_WATCHDOG(); /* feeds the dog */
... ...
} /* loop forever */
this can avoid watchdog reset.
=====================================================
this answer is for you. if it helps, please click on "correct answer " button. thanks!
Best Regards,
Jennie
hi Vikas,
from your description, your program got reset when running in loop.
I wonder the reset was caused by COP. please try to add feed dog code inside for() loop:
for example:;
for(;;) {
... ...
__RESET_WATCHDOG(); /* feeds the dog */
... ...
} /* loop forever */
this can avoid watchdog reset.
=====================================================
this answer is for you. if it helps, please click on "correct answer " button. thanks!
Best Regards,
Jennie
thanks zhang jennie the problem was solved
you are welcome.
Best Regards,
Jennie