⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extint_8c-source.html

📁 单片机的软件
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: extint.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>extint.c</h1><a href="extint_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file extint.c \brief External-Interrupt function library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'extint.c'</span>00005 <span class="comment">// Title        : External-Interrupt function library</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2002-2004</span>00007 <span class="comment">// Created      : 5/10/2002</span>00008 <span class="comment">// Revised      : 11/16/2004</span>00009 <span class="comment">// Version      : 1.0</span>00010 <span class="comment">// Target MCU   : Atmel AVR Series</span>00011 <span class="comment">// Editor Tabs  : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// Notes:   This library provides convenient standardized configuration and</span>00014 <span class="comment">//          access to external interrupts.  The library is designed to make</span>00015 <span class="comment">//          it possible to write code that uses external interrupts without</span>00016 <span class="comment">//          digging into the processor datasheets to find register names and</span>00017 <span class="comment">//          bit-defines.  The library also strives to allow code which uses</span>00018 <span class="comment">//          external interrupts to more easily cross-compile between different</span>00019 <span class="comment">//          microcontrollers.</span>00020 <span class="comment">//</span>00021 <span class="comment">//          NOTE: Using this library has certain advantages, but also adds</span>00022 <span class="comment">//          overhead and latency to interrupt servicing.  If the smallest</span>00023 <span class="comment">//          code size or fastest possible latency is needed, do NOT use this</span>00024 <span class="comment">//          library; link your interrupts directly.</span>00025 <span class="comment">//</span>00026 <span class="comment">//*****************************************************************************</span>00027 00028 <span class="preprocessor">#include &lt;avr/io.h&gt;</span>00029 <span class="preprocessor">#include &lt;avr/signal.h&gt;</span>00030 <span class="preprocessor">#include &lt;avr/interrupt.h&gt;</span>00031 00032 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00033 <span class="preprocessor">#include "<a class="code" href="extint_8h.html">extint.h</a>"</span>00034 00035 <span class="comment">// Global variables</span>00036 <span class="keyword">typedef</span> void (*voidFuncPtr)(void);00037 <span class="keyword">volatile</span> <span class="keyword">static</span> voidFuncPtr ExtIntFunc[EXTINT_NUM_INTERRUPTS];00038 00039 <span class="comment">// functions</span>00040 <span class="comment"></span>00041 <span class="comment">//! initializes extint library</span><a name="l00042"></a><a class="code" href="extint_8h.html#a14">00042</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a2">extintInit</a>(<span class="keywordtype">void</span>)00043 {00044     u08 intNum;00045     <span class="comment">// detach all user functions from interrupts</span>00046     <span class="keywordflow">for</span>(intNum=0; intNum&lt;EXTINT_NUM_INTERRUPTS; intNum++)00047         <a class="code" href="extint_8c.html#a5">extintDetach</a>(intNum);00048 00049 }00050 <span class="comment"></span>00051 <span class="comment">//! Configure external interrupt trigger</span>00052 <span class="comment"></span><span class="comment">// NOTE: this function is not complete!!!</span><a name="l00053"></a><a class="code" href="extint_8h.html#a15">00053</a> <span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a3">extintConfigure</a>(u08 interruptNum, u08 configuration)00054 {00055     <span class="keywordflow">if</span>(interruptNum == <a class="code" href="extint_8h.html#a0">EXTINT0</a>)00056     {00057         MCUCR &amp;= ~((1&lt;&lt;ISC01) | (1&lt;&lt;ISC00));00058         MCUCR |= configuration;00059     }00060 <span class="preprocessor">    #ifdef SIG_INTERRUPT1</span>00061 <span class="preprocessor"></span>    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(interruptNum == <a class="code" href="extint_8h.html#a1">EXTINT1</a>)00062     {00063         MCUCR &amp;= ~((1&lt;&lt;ISC11) | (1&lt;&lt;ISC10));00064         MCUCR |= configuration&lt;&lt;2;00065     }00066 <span class="preprocessor">    #endif</span>00067 <span class="preprocessor"></span><span class="preprocessor">    #ifdef SIG_INTERRUPT2</span>00068 <span class="preprocessor"></span>    <span class="keywordflow">else</span> <span class="keywordflow">if</span>(interruptNum == <a class="code" href="extint_8h.html#a2">EXTINT2</a>)00069     {00070         <span class="keywordflow">if</span>(configuration == <a class="code" href="extint_8h.html#a11">EXTINT_EDGE_RISING</a>)00071             sbi(MCUCSR, ISC2);00072         <span class="keywordflow">else</span>00073             cbi(MCUCSR, ISC2);00074     }00075 <span class="preprocessor">    #endif</span>00076 <span class="preprocessor"></span>    <span class="comment">// need to handle a lot more cases</span>00077     <span class="comment">// and differences between processors.</span>00078     <span class="comment">// looking for clean way to do it...</span>00079 }00080 <span class="comment"></span>00081 <span class="comment">//! Attach a user function to an external interrupt</span><a name="l00082"></a><a class="code" href="extint_8h.html#a16">00082</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a4">extintAttach</a>(u08 interruptNum, <span class="keywordtype">void</span> (*userHandler)(<span class="keywordtype">void</span>) )00083 {00084     <span class="comment">// make sure the interrupt number is within bounds</span>00085     <span class="keywordflow">if</span>(interruptNum &lt; EXTINT_NUM_INTERRUPTS)00086     {00087         <span class="comment">// set the interrupt function to run</span>00088         <span class="comment">// the supplied user's function</span>00089         ExtIntFunc[interruptNum] = userHandler;00090     }00091 }00092 <span class="comment"></span>00093 <span class="comment">//! Detach a user function from an external interrupt</span><a name="l00094"></a><a class="code" href="extint_8h.html#a17">00094</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a5">extintDetach</a>(u08 interruptNum)00095 {00096     <span class="comment">// make sure the interrupt number is within bounds</span>00097     <span class="keywordflow">if</span>(interruptNum &lt; EXTINT_NUM_INTERRUPTS)00098     {00099         <span class="comment">// set the interrupt function to run</span>00100         <span class="comment">// the supplied user's function</span>00101         ExtIntFunc[interruptNum] = 0;00102     }00103 }00104 <span class="comment"></span>00105 <span class="comment">//! Interrupt handler for INT0</span><a name="l00106"></a><a class="code" href="extint_8c.html#a6">00106</a> <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT0)00107 {00108     <span class="comment">// if a user function is defined, execute it</span>00109     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a0">EXTINT0</a>])00110         ExtIntFunc[<a class="code" href="extint_8h.html#a0">EXTINT0</a>]();00111 }00112 00113 <span class="preprocessor">#ifdef SIG_INTERRUPT1</span>00114 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT1</span>00115 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT1)00116 {00117     <span class="comment">// if a user function is defined, execute it</span>00118     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a1">EXTINT1</a>])00119         ExtIntFunc[<a class="code" href="extint_8h.html#a1">EXTINT1</a>]();00120 }00121 <span class="preprocessor">#endif</span>00122 <span class="preprocessor"></span>00123 <span class="preprocessor">#ifdef SIG_INTERRUPT2</span>00124 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT2</span>00125 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT2)00126 {00127     <span class="comment">// if a user function is defined, execute it</span>00128     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a2">EXTINT2</a>])00129         ExtIntFunc[<a class="code" href="extint_8h.html#a2">EXTINT2</a>]();00130 }00131 <span class="preprocessor">#endif</span>00132 <span class="preprocessor"></span>00133 <span class="preprocessor">#ifdef SIG_INTERRUPT3</span>00134 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT3</span>00135 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT3)00136 {00137     <span class="comment">// if a user function is defined, execute it</span>00138     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a3">EXTINT3</a>])00139         ExtIntFunc[<a class="code" href="extint_8h.html#a3">EXTINT3</a>]();00140 }00141 <span class="preprocessor">#endif</span>00142 <span class="preprocessor"></span>00143 <span class="preprocessor">#ifdef SIG_INTERRUPT4</span>00144 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT4</span>00145 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT4)00146 {00147     <span class="comment">// if a user function is defined, execute it</span>00148     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a4">EXTINT4</a>])00149         ExtIntFunc[<a class="code" href="extint_8h.html#a4">EXTINT4</a>]();00150 }00151 <span class="preprocessor">#endif</span>00152 <span class="preprocessor"></span>00153 <span class="preprocessor">#ifdef SIG_INTERRUPT5</span>00154 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT5</span>00155 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT5)00156 {00157     <span class="comment">// if a user function is defined, execute it</span>00158     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a5">EXTINT5</a>])00159         ExtIntFunc[<a class="code" href="extint_8h.html#a5">EXTINT5</a>]();00160 }00161 <span class="preprocessor">#endif</span>00162 <span class="preprocessor"></span>00163 <span class="preprocessor">#ifdef SIG_INTERRUPT6</span>00164 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT6</span>00165 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT6)00166 {00167     <span class="comment">// if a user function is defined, execute it</span>00168     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a6">EXTINT6</a>])00169         ExtIntFunc[<a class="code" href="extint_8h.html#a6">EXTINT6</a>]();00170 }00171 <span class="preprocessor">#endif</span>00172 <span class="preprocessor"></span>00173 <span class="preprocessor">#ifdef SIG_INTERRUPT7</span>00174 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT7</span>00175 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT7)00176 {00177     <span class="comment">// if a user function is defined, execute it</span>00178     <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a7">EXTINT7</a>])00179         ExtIntFunc[<a class="code" href="extint_8h.html#a7">EXTINT7</a>]();00180 }00181 <span class="preprocessor">#endif</span>00182 <span class="preprocessor"></span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Aug 22 04:29:27 2005 for Procyon AVRlib by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -