📄 uart_8h.html
字号:
<td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>RX interrupt handler. <p>RX interrupt handler. RX interrupt always enabled. <p>Definition at line <a class="el" href="uart_8c-source.html#l00146">146</a> of file <a class="el" href="uart_8c-source.html">uart.c</a>.<p>References <a class="el" href="global_8h-source.html#l00033">GLOBAL_FLAGS::cmd</a>, <a class="el" href="global_8h-source.html#l00025">FALSE</a>, <a class="el" href="global_8h-source.html#l00031">GLOBAL_FLAGS::running</a>, <a class="el" href="main_8c-source.html#l00033">status</a>, <a class="el" href="global_8h-source.html#l00024">TRUE</a>, <a class="el" href="uart_8h-source.html#l00024">UART_RX_BUFFER_SIZE</a>, <a class="el" href="uart_8c-source.html#l00027">UART_RxBuffer</a>, <a class="el" href="uart_8c-source.html#l00029">UART_RxPtr</a>, and <a class="el" href="uart_8c-source.html#l00073">uart_SendByte()</a>.<p><pre class="fragment"><div>00147 {00148 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data;00149 00150 <span class="comment">// Read the received data.</span>00151 data = UDR0;00152 00153 <span class="keywordflow">if</span>(<a class="code" href="main_8c.html#a0">status</a>.<a class="code" href="structGLOBAL__FLAGS.html#o2">running</a> == <a class="code" href="global_8h.html#a1">FALSE</a>){00154 <span class="comment">// If backspace.</span>00155 <span class="keywordflow">if</span>(data == <span class="charliteral">'\b'</span>)00156 {00157 <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a2">UART_RxPtr</a>)00158 <span class="comment">// Done if not at beginning of buffer.</span>00159 {00160 <a class="code" href="uart_8h.html#a8">uart_SendByte</a>(<span class="charliteral">'\b'</span>);00161 <a class="code" href="uart_8h.html#a8">uart_SendByte</a>(<span class="charliteral">' '</span>);00162 <a class="code" href="uart_8h.html#a8">uart_SendByte</a>(<span class="charliteral">'\b'</span>);00163 <a class="code" href="uart_8c.html#a2">UART_RxPtr</a>--;00164 <a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[<a class="code" href="uart_8c.html#a2">UART_RxPtr</a>]=0x00;00165 }00166 }00167 <span class="comment">// Not backspace.</span>00168 <span class="keywordflow">else</span>00169 {00170 <span class="comment">// Put the data into RxBuf</span>00171 <span class="comment">// and place 0x00 after it. If buffer is full,</span>00172 <span class="comment">// data is written to UART_RX_BUFFER_SIZE - 1.</span>00173 <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a2">UART_RxPtr</a> < (<a class="code" href="uart_8h.html#a0">UART_RX_BUFFER_SIZE</a> - 1)){00174 <a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[<a class="code" href="uart_8c.html#a2">UART_RxPtr</a>] = data;00175 <a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[<a class="code" href="uart_8c.html#a2">UART_RxPtr</a> + 1]=0x00;00176 <a class="code" href="uart_8c.html#a2">UART_RxPtr</a>++;00177 }00178 <span class="keywordflow">else</span>00179 {00180 <a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[<a class="code" href="uart_8c.html#a2">UART_RxPtr</a> - 1] = data;00181 <a class="code" href="uart_8h.html#a8">uart_SendByte</a>(<span class="charliteral">'\b'</span>);00182 }00183 <span class="comment">// If enter.</span>00184 <span class="keywordflow">if</span>(data == 13){00185 <a class="code" href="main_8c.html#a0">status</a>.<a class="code" href="structGLOBAL__FLAGS.html#o0">cmd</a> = <a class="code" href="global_8h.html#a0">TRUE</a>;00186 }00187 <span class="keywordflow">else</span>00188 <a class="code" href="uart_8h.html#a8">uart_SendByte</a>(data);00189 }00190 }00191 }</div></pre><p>Here is the call graph for this function:<p><center><img src="uart_8h_a12_cgraph.png" border="0" usemap="#uart_8h_a12_cgraph_map" alt=""></center><map name="uart_8h_a12_cgraph_map"><area href="uart_8h.html#a8" shape="rect" coords="198,7,307,33" alt=""></map> </td> </tr></table><a class="anchor" name="a8" doxytag="uart.h::uart_SendByte" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void uart_SendByte </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">unsigned char </td> <td class="mdname1" valign="top" nowrap> <em>data</em> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>send a byte. <p>Puts a byte in TX buffer and starts uart TX interrupt. If TX buffer is full it will hang until space.<p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td></td><td valign=top><em>data</em> </td><td>Data to be sent. </td></tr> </table></dl><p>Definition at line <a class="el" href="uart_8c-source.html#l00073">73</a> of file <a class="el" href="uart_8c-source.html">uart.c</a>.<p>References <a class="el" href="uart_8h-source.html#l00036">SET_UDRIE</a>, and <a class="el" href="uart_8h-source.html#l00031">UART_TX_BUFFER_MASK</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00173">ShowHelp()</a>, <a class="el" href="uart_8c-source.html#l00146">UART_RX_interrupt()</a>, <a class="el" href="uart_8c-source.html#l00111">uart_SendInt()</a>, and <a class="el" href="uart_8c-source.html#l00097">uart_SendString()</a>.<p><pre class="fragment"><div>00074 {00075 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> tmphead;00076 00077 <span class="comment">// Calculate buffer index</span>00078 tmphead = ( UART_TxHead + 1 ) & <a class="code" href="uart_8h.html#a3">UART_TX_BUFFER_MASK</a>;00079 <span class="comment">// Wait for free space in buffer</span>00080 <span class="keywordflow">while</span> ( tmphead == UART_TxTail )00081 ;00082 <span class="comment">// Store data in buffer</span>00083 UART_TxBuffer[tmphead] = data;00084 <span class="comment">// Store new index</span>00085 UART_TxHead = tmphead;00086 <span class="comment">// Enable UDRE interrupt</span>00087 <a class="code" href="uart_8h.html#a4">SET_UDRIE</a>;00088 }</div></pre> </td> </tr></table><a class="anchor" name="a10" doxytag="uart.h::uart_SendInt" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void uart_SendInt </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">int </td> <td class="mdname1" valign="top" nowrap> <em>x</em> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Sends a integer. <p>Converts a integer to ASCII and sends it using uart_SendByte. If TX buffer is full it will hang until space.<p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td></td><td valign=top><em>x</em> </td><td>Integer to be sent. </td></tr> </table></dl><p>Definition at line <a class="el" href="uart_8c-source.html#l00111">111</a> of file <a class="el" href="uart_8c-source.html">uart.c</a>.<p>References <a class="el" href="uart_8c-source.html#l00073">uart_SendByte()</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00190">ShowData()</a>.<p><pre class="fragment"><div>00112 {00113 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> dec[] = <span class="stringliteral">"0123456789"</span>;00114 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> div_val = 10000;00115 00116 <span class="keywordflow">if</span> (x < 0){00117 x = - x;00118 <a class="code" href="uart_8h.html#a8">uart_SendByte</a>(<span class="charliteral">'-'</span>);00119 }00120 <span class="keywordflow">while</span> (div_val > 1 && div_val > x)00121 div_val /= 10;00122 <span class="keywordflow">do</span>{00123 <a class="code" href="uart_8h.html#a8">uart_SendByte</a> (dec[x / div_val]);00124 x %= div_val;00125 div_val /= 10;00126 }<span class="keywordflow">while</span>(div_val);00127 }</div></pre><p>Here is the call graph for this function:<p><center><img src="uart_8h_a10_cgraph.png" border="0" usemap="#uart_8h_a10_cgraph_map" alt=""></center><map name="uart_8h_a10_cgraph_map"><area href="uart_8h.html#a8" shape="rect" coords="155,7,264,33" alt=""></map> </td> </tr></table><a class="anchor" name="a9" doxytag="uart.h::uart_SendString" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> void uart_SendString </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">unsigned char </td> <td class="mdname1" valign="top" nowrap> <em>Str</em>[] </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Sends a string. <p>Loops thru a string and send each byte with uart_SendByte. If TX buffer is full it will hang until space.<p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td></td><td valign=top><em>Str</em> </td><td>String to be sent. </td></tr> </table></dl><p>Definition at line <a class="el" href="uart_8c-source.html#l00097">97</a> of file <a class="el" href="uart_8c-source.html">uart.c</a>.<p>References <a class="el" href="uart_8c-source.html#l00073">uart_SendByte()</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00062">main()</a>, and <a class="el" href="main_8c-source.html#l00190">ShowData()</a>.<p><pre class="fragment"><div>00098 {00099 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> n = 0;00100 <span class="keywordflow">while</span>(Str[n])00101 <a class="code" href="uart_8h.html#a8">uart_SendByte</a>(Str[n++]);00102 }</div></pre><p>Here is the call graph for this function:<p><center><img src="uart_8h_a9_cgraph.png" border="0" usemap="#uart_8h_a9_cgraph_map" alt=""></center><map name="uart_8h_a9_cgraph_map"><area href="uart_8h.html#a8" shape="rect" coords="176,7,285,33" alt=""></map> </td> </tr></table><a class="anchor" name="a13" doxytag="uart.h::UART_TX_interrupt" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> __interrupt void UART_TX_interrupt </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>TX interrupt handler. <p>TX interrupt handler. TX interrupt turned on by uart_SendByte, turned off when TX buffer is empty. <p>Definition at line <a class="el" href="uart_8c-source.html#l00200">200</a> of file <a class="el" href="uart_8c-source.html">uart.c</a>.<p>References <a class="el" href="uart_8h-source.html#l00037">CLR_UDRIE</a>, and <a class="el" href="uart_8h-source.html#l00031">UART_TX_BUFFER_MASK</a>.<p><pre class="fragment"><div>00201 {00202 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> UART_TxTail_tmp;00203 UART_TxTail_tmp = UART_TxTail;00204 00205 <span class="comment">// Check if all data is transmitted</span>00206 <span class="keywordflow">if</span> ( UART_TxHead != UART_TxTail_tmp )00207 {00208 <span class="comment">// Calculate buffer index</span>00209 UART_TxTail_tmp = ( UART_TxTail + 1 ) & <a class="code" href="uart_8h.html#a3">UART_TX_BUFFER_MASK</a>;00210 <span class="comment">// Store new index</span>00211 UART_TxTail = UART_TxTail_tmp;00212 <span class="comment">// Start transmition</span>00213 UDR0= UART_TxBuffer[ UART_TxTail_tmp];00214 }00215 <span class="keywordflow">else</span>00216 <span class="comment">// Disable UDRE interrupt</span>00217 <a class="code" href="uart_8h.html#a5">CLR_UDRIE</a>;00218 }</div></pre> </td> </tr></table><hr><h2>Variable Documentation</h2><a class="anchor" name="a6" doxytag="uart.h::UART_RxBuffer" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> unsigned char <a class="el" href="uart_8h.html#a6">UART_RxBuffer</a>[UART_RX_BUFFER_SIZE] </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Buffer with received string from uart. <p><p>Definition at line <a class="el" href="uart_8h-source.html#l00046">46</a> of file <a class="el" href="uart_8h-source.html">uart.h</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00062">main()</a>, <a class="el" href="uart_8c-source.html#l00135">uart_FlushRxBuffer()</a>, and <a class="el" href="uart_8c-source.html#l00146">UART_RX_interrupt()</a>. </td> </tr></table><hr size="1"><address style="align: right;"><small>Generated on Mon May 8 15:05:04 2006 for AVR446 - Linear speed control of stepper motor by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -