User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
672
Library Example
Example demonstrates function cross calling using setjmp and longjmp functions. When called, Setjmp() saves its
calling environment in its buf argument for later use by the Longjmp(). Longjmp(), on the other hand, restores the
environment saved by the most recent invocation of the Setjmp() with the corresponding buf argument.
Copy Code To Clipboard
program Setjmp;
var buf : array[4] of word ; // Note : Program ow diagrams are indexed according
// to the sequence of execution
procedure func33(); // 2<------------|
begin // |
Delay_ms(1000); // |
// |
nop; // |
longjmp(buf, 2); // 3---------------->|
nop; // | |
// | |
end; // | |
// | |
procedure func(); // 1<--------| | |
begin // | | |
PORTB := 3; // | | |
if (setjmp(buf) = 2) then // 3<----------------|
PORTB := 1 // 4-->| | |
else // | | |
func33(); // 2------------>|
// | |
// 4<--| |
end; // 5----->| |
// | |
begin // | |
ADPCFG := 0xFFFF; // | |
// | |
PORTB := 0; // | |
TRISB := 0; // | |
// | |
nop; // | |
// | |
func(); // 1-------->|
// |
nop; // 5<-----|
Delay_ms(1000);
PORTB := 0xFFFF;
end.