Added two new source files to the project: lkmem.c and lkaomf51.c
[fw/sdcc] / doc / sdccman.html / node26.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
3 <!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
4 original version by:  Nikos Drakos, CBLU, University of Leeds
5 * revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
6 * with significant contributions from:
7   Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
8 <HTML>
9 <HEAD>
10 <TITLE>3.7 Interrupt Service Routines</TITLE>
11 <META NAME="description" CONTENT="3.7 Interrupt Service Routines">
12 <META NAME="keywords" CONTENT="sdccman">
13 <META NAME="resource-type" CONTENT="document">
14 <META NAME="distribution" CONTENT="global">
15
16 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
17 <META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
18 <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
19
20 <LINK REL="STYLESHEET" HREF="sdccman.css">
21
22 <LINK REL="next" HREF="node27.html">
23 <LINK REL="previous" HREF="node25.html">
24 <LINK REL="up" HREF="node19.html">
25 <LINK REL="next" HREF="node27.html">
26 </HEAD>
27
28 <BODY >
29 <!--Navigation Panel-->
30 <A NAME="tex2html640"
31  HREF="node27.html">
32 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
33 <A NAME="tex2html634"
34  HREF="node19.html">
35 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
36 <A NAME="tex2html628"
37  HREF="node25.html">
38 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
39 <A NAME="tex2html636"
40  HREF="node1.html">
41 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
42 <A NAME="tex2html638"
43  HREF="node61.html">
44 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
45 <BR>
46 <B> Next:</B> <A NAME="tex2html641"
47  HREF="node27.html">3.8 Critical Functions</A>
48 <B> Up:</B> <A NAME="tex2html635"
49  HREF="node19.html">3. Using SDCC</A>
50 <B> Previous:</B> <A NAME="tex2html629"
51  HREF="node25.html">3.6 Overlaying</A>
52  &nbsp <B>  <A NAME="tex2html637"
53  HREF="node1.html">Contents</A></B> 
54  &nbsp <B>  <A NAME="tex2html639"
55  HREF="node61.html">Index</A></B> 
56 <BR>
57 <BR>
58 <!--End of Navigation Panel-->
59
60 <H2><A NAME="SECTION00047000000000000000">
61 3.7 Interrupt Service Routines</A>
62 </H2>
63
64 <P>
65 SDCC allows interrupt service routines to be coded in C, with some
66 extended keywords.
67 <BR>
68
69 <BR>
70 <TT>void timer_isr (void) interrupt 2 using 1 </TT>&nbsp;
71 <BR>
72 <TT>{ </TT>&nbsp;
73 <BR>
74 <TT>.. </TT>&nbsp;
75 <BR>
76 <TT>}</TT>&nbsp;
77 <BR>&nbsp;
78 <BR>
79 The number following the <I>interrupt</I> keyword is the interrupt
80 number this routine will service. The compiler will insert a call
81 to this routine in the interrupt vector table for the interrupt number
82 specified. The <I>using</I> keyword is used to tell the compiler to
83 use the specified register bank (8051 specific) when generating code
84 for this function. Note that when some function is called from an
85 interrupt service routine it should be preceded by a #pragma&nbsp;NOOVERLAY
86 if it is not reentrant. A special note here, int (16 bit) and long
87 (32 bit) integer division, multiplication &amp; modulus operations are
88 implemented using external support routines developed in ANSI-C, if
89 an interrupt service routine needs to do any of these operations then
90 the support routines (as mentioned in a following section) will have
91 to be recompiled using the <I>-stack-auto</I> option and the source
92 file will need to be compiled using the <I>-int-long-ren</I>t compiler
93 option.
94
95 <P>
96 If you have multiple source files in your project, interrupt service
97 routines can be present in any of them, but a prototype of the isr
98 MUST be present or included in the file that contains the function
99 <I>main</I>.
100
101 <P>
102 Interrupt Numbers and the corresponding address &amp; descriptions for
103 the Standard 8051 are listed below. SDCC will automatically adjust
104 the interrupt vector table to the maximum interrupt number specified.
105 <BR>
106
107 <P>
108  
109 <TABLE CELLPADDING=3 BORDER="1">
110 <TR><TD ALIGN="CENTER">Interrupt #</TD>
111 <TD ALIGN="CENTER">Description</TD>
112 <TD ALIGN="CENTER">Vector Address</TD>
113 </TR>
114 <TR><TD ALIGN="CENTER">0</TD>
115 <TD ALIGN="CENTER">External 0</TD>
116 <TD ALIGN="CENTER">0x0003</TD>
117 </TR>
118 <TR><TD ALIGN="CENTER">1</TD>
119 <TD ALIGN="CENTER">Timer 0</TD>
120 <TD ALIGN="CENTER">0x000B</TD>
121 </TR>
122 <TR><TD ALIGN="CENTER">2</TD>
123 <TD ALIGN="CENTER">External 1</TD>
124 <TD ALIGN="CENTER">0x0013</TD>
125 </TR>
126 <TR><TD ALIGN="CENTER">3</TD>
127 <TD ALIGN="CENTER">Timer 1</TD>
128 <TD ALIGN="CENTER">0x001B</TD>
129 </TR>
130 <TR><TD ALIGN="CENTER">4</TD>
131 <TD ALIGN="CENTER">Serial</TD>
132 <TD ALIGN="CENTER">0x0023</TD>
133 </TR>
134 </TABLE>
135 <BR>
136
137 <BR>
138 If the interrupt service routine is defined without <I>using</I> a
139 register bank or with register bank 0 (using 0), the compiler will
140 save the registers used by itself on the stack upon entry and restore
141 them at exit, however if such an interrupt service routine calls another
142 function then the entire register bank will be saved on the stack.
143 This scheme may be advantageous for small interrupt service routines
144 which have low register usage.
145
146 <P>
147 If the interrupt service routine is defined to be using a specific
148 register bank then only <I>a, b &amp; dptr</I> are save and restored,
149 if such an interrupt service routine calls another function (using
150 another register bank) then the entire register bank of the called
151 function will be saved on the stack. This scheme is recommended for
152 larger interrupt service routines.
153
154 <P>
155 Calling other functions from an interrupt service routine is not recommended,
156 avoid it if possible.
157 <BR>
158
159 <BR>
160 Also see the _naked modifier.
161
162 <P>
163 <HR>
164 <!--Navigation Panel-->
165 <A NAME="tex2html640"
166  HREF="node27.html">
167 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
168 <A NAME="tex2html634"
169  HREF="node19.html">
170 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
171 <A NAME="tex2html628"
172  HREF="node25.html">
173 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
174 <A NAME="tex2html636"
175  HREF="node1.html">
176 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
177 <A NAME="tex2html638"
178  HREF="node61.html">
179 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
180 <BR>
181 <B> Next:</B> <A NAME="tex2html641"
182  HREF="node27.html">3.8 Critical Functions</A>
183 <B> Up:</B> <A NAME="tex2html635"
184  HREF="node19.html">3. Using SDCC</A>
185 <B> Previous:</B> <A NAME="tex2html629"
186  HREF="node25.html">3.6 Overlaying</A>
187  &nbsp <B>  <A NAME="tex2html637"
188  HREF="node1.html">Contents</A></B> 
189  &nbsp <B>  <A NAME="tex2html639"
190  HREF="node61.html">Index</A></B> 
191 <!--End of Navigation Panel-->
192 <ADDRESS>
193 <I>Johan Knol</I>
194 <BR><I>2001-07-13</I>
195 </ADDRESS>
196 </BODY>
197 </HTML>