SW006014 Microchip Technology, SW006014 Datasheet - Page 42

C COMPILER MPLAB FOR PIC24 MCU

SW006014

Manufacturer Part Number
SW006014
Description
C COMPILER MPLAB FOR PIC24 MCU
Manufacturer
Microchip Technology
Type
MPLAB® C Compilerr
Series
PIC24r
Datasheet

Specifications of SW006014

Supported Families
PIC24
Core Architecture
PIC
Kit Contents
Software And Docs
Mcu Supported Families
PIC24
Tool Function
Compiler
Tool Type
Compiler
Processor Series
PIC24
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
PIC24
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
DS51456E-page 38
signal
Description:
Include:
Prototype:
Arguments:
Return Value:
Example:
Controls interrupt signal handling.
<signal.h>
void (*signal(int sig, void(*func)(int)))(int);
sig
func
Returns the previous value of func.
#include <signal.h> /* for signal, raise, */
#include <stdio.h>
/* Signal handler function */
void mysigint(int id)
{
}
int main(void)
{
}
Output:
SIGINT received
SIGILL was ignored
FPE
Explanation:
The function mysigint is the user-defined signal handler for SIGINT.
Inside the main program, the function signal is called to set up the
signal handler (mysigint) for the signal SIGINT that will override the
default actions. The function raise is called to report the signal
SIGINT. This causes the signal handler for SIGINT to use the
user-defined function (mysigint) as the signal handler so it prints the
"SIGINT received" message.
Next, the function signal is called to set up the signal handler
SIG_IGN for the signal SIGILL. The constant SIG_IGN is used to indi-
cate the signal should be ignored. The function raise is called to
report the signal SIGILL that is ignored.
The function raise is called again to report the signal SIGFPE. Since
there is no user defined function for SIGFPE, the default signal handler
is used so the message "FPE" is printed (which stands for
"arithmetic error - terminating”). Then the calling program is
terminated. The printf statement is never reached.
printf("SIGINT received\n");
/* Override default with user defined function */
signal(SIGINT, mysigint);
raise(SIGINT);
/* Ignore signal handler */
signal(SIGILL, SIG_IGN);
raise(SIGILL);
printf("SIGILL was ignored\n");
/* Use default signal handler */
raise(SIGFPE);
printf("Program never reaches here.");
signal name
function to be executed
/* SIGINT, SIGILL, */
/* SIG_IGN, and SIGFPE */
/* for printf */
© 2008 Microchip Technology Inc.

Related parts for SW006014