View previous topic :: View next topic |
Author |
Message |
Kieran
Joined: 28 Nov 2003 Posts: 39 Location: Essex UK
|
PCH functions setjmp and longjmp |
Posted: Mon Mar 22, 2004 12:04 pm |
|
|
I have used these functions successfully with a PIC16F876 but when using them with a PIC18F452 the programme crashes and resets via the watchdog when I execute the longjmp.
Code: | #include <setjmp.h>
jmp_buf myenv;
// in main
do
{
restart_WDT();
setjmp(myenv); // Back to here
// in a function
do
{
key = fetch_key(); // wait for key press
if (key == 'C') // abort key ?
{
err = 0;
longjmp(myenv,1); // should jump to main but crashes
}
}
while (key != 'E'); |
Compiler version 3.184
Anyone got these to work on a PIC18Fxxx ?
Thanks |
|
 |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Mar 23, 2004 12:33 am |
|
|
Are you kicking the watchdog in the fetch_key() function? If not, that may cause the program to reset.
It's hard to say what the problem is. Post your full code (incluing the setjmp.h file) so we can take a look at it. |
|
 |
Kieran
Joined: 28 Nov 2003 Posts: 39 Location: Essex UK
|
|
Posted: Tue Mar 23, 2004 9:29 am |
|
|
The fetch_key() function includes a delay_ms function with watchdog.
The code for the full project is long, I am trying a stripped down version (which works!). So I will try to reintroduce the bug then post it. |
|
 |
Kieran
Joined: 28 Nov 2003 Posts: 39 Location: Essex UK
|
|
Posted: Wed Mar 24, 2004 5:08 am |
|
|
After further testing I have given up with the longjmp approach. It worked sometimes, no time to debug further.
Thanks |
|
 |
|