go to single .html
[fw/sdcc] / doc / SDCCUdoc-11.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4  <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
5  <TITLE>SDCC Compiler User Guide: Interrupt Service Routines</TITLE>
6  <LINK HREF="SDCCUdoc-12.html" REL=next>
7  <LINK HREF="SDCCUdoc-10.html" REL=previous>
8  <LINK HREF="SDCCUdoc.html#toc11" REL=contents>
9 </HEAD>
10 <BODY>
11 <A HREF="SDCCUdoc-12.html">Next</A>
12 <A HREF="SDCCUdoc-10.html">Previous</A>
13 <A HREF="SDCCUdoc.html#toc11">Contents</A>
14 <HR>
15 <H2><A NAME="Interrupt Service Rouines"></A> <A NAME="s11">11. Interrupt Service Routines</A> </H2>
16
17 <P>SDCC allows interrupt service routines to be coded in C, with some extended
18 keywords.
19 <P>
20 <PRE>
21 void timer_isr (void) interrupt 2 using 1 
22
23 .. 
24 }
25  
26 </PRE>
27 <P>The number following the 'interrupt' keyword is the interrupt number this
28 routine will service. The compiler will insert a call to this routine in the
29 interrupt vector table for the interrupt number specified. The 'using' keyword
30 is used to tell the compiler to use the specified register bank (8051 specific)
31 when generating code for this function. Note that when some function is called
32 from an interrupt service routine it should be preceded by a #pragma NOOVERLAY
33 (if it is not reentrant) . A special note here, int (16 bit) and long (32 bit)
34 integer division, multiplication &amp; modulus operations are implemented using
35 external support routines developed in ANSI-C, if an interrupt service routine
36 needs to do any of these operations then the support routines (as mentioned
37 in a following section) will have to recompiled using the --stack-auto option
38 and the source file will need to be compiled using the --int-long-rent compiler
39 option.
40 <P>If you have multiple source files in your project, interrupt service routines
41 can be present in any of them, but a prototype of the isr MUST be present in
42 the file that contains the function 'main'.
43 <P>Interrupt Numbers and the corresponding address &amp; descriptions for
44 the Standard 8051 are listed below. SDCC will automatically adjust the interrupt
45 vector table to the maximum interrupt number specified.
46 <P>
47 <PRE>
48 Interrupt #         Description           Vector Address 
49    0                External
50  0            0x0003 
51    1                Timer 0               0x000B 
52    2
53                 External 1            0x0013 
54    3                Timer 1               0x001B
55  
56    4                Serial                0x0023
57  
58 </PRE>
59 <P>If the interrupt service routine is defined without a register bank or
60 with register bank 0 (using 0), the compiler will save the registers used by
61 itself on the stack (upon entry and restore them at exit), however if such
62 an interrupt service routine calls another function then the entire register
63 bank will be saved on the stack. This scheme may be advantageous for small
64 interrupt service routines which have low register usage.
65 <P>If the interrupt service routine is defined to be using a specific register
66 bank then only "a","b" &amp; "dptr" are save and restored, if such an interrupt service
67 routine calls another function (using another register bank) then the entire
68 register bank of the called function will be saved on the stack. This scheme
69 is recommended for larger interrupt service routines.
70 <P>Calling other functions from an interrupt service routine is not recommended
71 avoid it if possible.
72 <HR>
73 <A HREF="SDCCUdoc-12.html">Next</A>
74 <A HREF="SDCCUdoc-10.html">Previous</A>
75 <A HREF="SDCCUdoc.html#toc11">Contents</A>
76 </BODY>
77 </HTML>