📄 uart_8h.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>AVR446 - Linear speed control of stepper motor: uart.h File Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div><h1>uart.h File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>Header file for <a class="el" href="uart_8c.html">uart.c</a>. <p><ul><li>File: <a class="el" href="uart_8h.html">uart.h</a></li><li>Compiler: IAR EWAAVR 4.11A</li><li>Supported devices: All devices with a 16 bit timer can be used. The example is written for ATmega48</li><li>AppNote: AVR446 - Linear speed control of stepper motor</li></ul><p><dl compact><dt><b>Author:</b></dt><dd>Atmel Corporation: <a href="http://www.atmel.com">http://www.atmel.com</a> <br> Support email: <a href="mailto:avr@atmel.com">avr@atmel.com</a></dd></dl><dl compact><dt><b>Name</b></dt><dd>RELEASE_1_0 </dd></dl><dl compact><dt><b>Revision</b></dt><dd>1.2 </dd></dl><dl compact><dt><b>RCSfile</b></dt><dd><a class="el" href="uart_8h.html">uart.h</a>,v </dd></dl><dl compact><dt><b>Date</b></dt><dd>2006/05/08 12:25:58 </dd></dl><p>Definition in file <a class="el" href="uart_8h-source.html">uart.h</a>.<p><p>This graph shows which files directly or indirectly include this file:<p><center><img src="uart_8h__dep__incl.png" border="0" usemap="#uart.hdep_map" alt="Included by dependency graph"></center><map name="uart.hdep_map"><area href="main_8c.html" shape="rect" coords="7,7,68,34" alt=""><area href="speed__cntr_8c.html" shape="rect" coords="92,7,188,34" alt=""><area href="uart_8c.html" shape="rect" coords="212,7,268,34" alt=""></map><p><a href="uart_8h-source.html">Go to the source code of this file.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Defines</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a5">CLR_UDRIE</a> (UCSR0B &= ~(1<<UDRIE0))</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a4">SET_UDRIE</a> (UCSR0B |= (1<<UDRIE0))</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a1">UART_RX_BUFFER_MASK</a> ( UART_RX_BUFFER_SIZE - 1 )</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a0">UART_RX_BUFFER_SIZE</a> 32</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a3">UART_TX_BUFFER_MASK</a> ( UART_TX_BUFFER_SIZE - 1 )</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a2">UART_TX_BUFFER_SIZE</a> 64</td></tr><tr><td colspan=2><br><h2>Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a7">InitUART</a> (void)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Init of uart. <a href="#a7"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a11">uart_FlushRxBuffer</a> (void)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Empties the uart RX buffer. <a href="#a11"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>__interrupt void </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a12">UART_RX_interrupt</a> (void)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">RX interrupt handler. <a href="#a12"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a8">uart_SendByte</a> (unsigned char data)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">send a byte. <a href="#a8"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a10">uart_SendInt</a> (int Tall)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Sends a integer. <a href="#a10"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a9">uart_SendString</a> (unsigned char Tab[])</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Sends a string. <a href="#a9"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>__interrupt void </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a13">UART_TX_interrupt</a> (void)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">TX interrupt handler. <a href="#a13"></a><br><br></td></tr><tr><td colspan=2><br><h2>Variables</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>unsigned char </td><td class="memItemRight" valign=bottom><a class="el" href="uart_8h.html#a6">UART_RxBuffer</a> [UART_RX_BUFFER_SIZE]</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Buffer with received string from uart. <a href="#a6"></a><br><br></td></tr></table><hr><h2>Define Documentation</h2><a class="anchor" name="a5" doxytag="uart.h::CLR_UDRIE" ></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"> #define CLR_UDRIE (UCSR0B &= ~(1<<UDRIE0)) </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><p>Definition at line <a class="el" href="uart_8h-source.html#l00037">37</a> of file <a class="el" href="uart_8h-source.html">uart.h</a>.<p>Referenced by <a class="el" href="uart_8c-source.html#l00200">UART_TX_interrupt()</a>. </td> </tr></table><a class="anchor" name="a4" doxytag="uart.h::SET_UDRIE" ></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"> #define SET_UDRIE (UCSR0B |= (1<<UDRIE0)) </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><p>Definition at line <a class="el" href="uart_8h-source.html#l00036">36</a> of file <a class="el" href="uart_8h-source.html">uart.h</a>.<p>Referenced by <a class="el" href="uart_8c-source.html#l00073">uart_SendByte()</a>. </td> </tr></table><a class="anchor" name="a1" doxytag="uart.h::UART_RX_BUFFER_MASK" ></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"> #define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1 ) </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><p>Definition at line <a class="el" href="uart_8h-source.html#l00025">25</a> of file <a class="el" href="uart_8h-source.html">uart.h</a>. </td> </tr></table><a class="anchor" name="a0" doxytag="uart.h::UART_RX_BUFFER_SIZE" ></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"> #define UART_RX_BUFFER_SIZE 32 </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><p>Definition at line <a class="el" href="uart_8h-source.html#l00024">24</a> of file <a class="el" href="uart_8h-source.html">uart.h</a>.<p>Referenced by <a class="el" href="uart_8c-source.html#l00146">UART_RX_interrupt()</a>. </td> </tr></table><a class="anchor" name="a3" doxytag="uart.h::UART_TX_BUFFER_MASK" ></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"> #define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1 ) </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><p>Definition at line <a class="el" href="uart_8h-source.html#l00031">31</a> of file <a class="el" href="uart_8h-source.html">uart.h</a>.<p>Referenced by <a class="el" href="uart_8c-source.html#l00073">uart_SendByte()</a>, and <a class="el" href="uart_8c-source.html#l00200">UART_TX_interrupt()</a>. </td> </tr></table><a class="anchor" name="a2" doxytag="uart.h::UART_TX_BUFFER_SIZE" ></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"> #define UART_TX_BUFFER_SIZE 64 </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><p>Definition at line <a class="el" href="uart_8h-source.html#l00030">30</a> of file <a class="el" href="uart_8h-source.html">uart.h</a>. </td> </tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="a7" doxytag="uart.h::InitUART" ></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 InitUART </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>Init of uart. <p>Setup uart. The <a class="el" href="uart_8c.html#a0">BAUD</a> value must be modified according to clock frqequency. Refer to datasheet for details. <p>Definition at line <a class="el" href="uart_8c-source.html#l00045">45</a> of file <a class="el" href="uart_8c-source.html">uart.c</a>.<p>References <a class="el" href="uart_8c.html#a0">BAUD</a>, and <a class="el" href="uart_8c-source.html#l00029">UART_RxPtr</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00042">Init()</a>.<p><pre class="fragment"><div>00046 {00047 <span class="comment">// Set baud rate. 19.2 kbps trasfer speed running at 8 MHz.</span>00048 <span class="comment">//#define BAUD 25</span>00049 <span class="comment">// Set baud rate. 19.2 kbps trasfer speed running at 3.6864 MHz.</span>00050 <span class="preprocessor">#define BAUD 11</span>00051 <span class="preprocessor"></span>00052 UBRR0H = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>)(<a class="code" href="uart_8c.html#a0">BAUD</a>>>8);00053 UBRR0L = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>)<a class="code" href="uart_8c.html#a0">BAUD</a>;00054 <span class="comment">/* Enable receiver and transmitter, rx and tx int */</span>00055 UCSR0B = (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0)|(1<<TXCIE0);00056 <span class="comment">/* Set frame format: 8data, 1stop bit */</span>00057 UCSR0C = (3<<UCSZ00);00058 00059 <span class="comment">// Flush Buffers</span>00060 <a class="code" href="uart_8c.html#a2">UART_RxPtr</a> = 0;00061 UART_TxTail = 0;00062 UART_TxHead = 0;00063 }</div></pre> </td> </tr></table><a class="anchor" name="a11" doxytag="uart.h::uart_FlushRxBuffer" ></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_FlushRxBuffer </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>Empties the uart RX buffer. <p>Empties the uart RX buffer.<p><dl compact><dt><b>Returns:</b></dt><dd>x Integer to be sent. </dd></dl><p>Definition at line <a class="el" href="uart_8c-source.html#l00135">135</a> of file <a class="el" href="uart_8c-source.html">uart.c</a>.<p>References <a class="el" href="uart_8c-source.html#l00027">UART_RxBuffer</a>, and <a class="el" href="uart_8c-source.html#l00029">UART_RxPtr</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00062">main()</a>.<p><pre class="fragment"><div>00135 {00136 <a class="code" href="uart_8c.html#a2">UART_RxPtr</a> = 0;00137 <a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[<a class="code" href="uart_8c.html#a2">UART_RxPtr</a>] = 0;00138 }</div></pre> </td> </tr></table><a class="anchor" name="a12" doxytag="uart.h::UART_RX_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_RX_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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -