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

📄 main_8c-source.html

📁 使用AVR单片机控制步进电机的软件代码
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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: main.c Source File</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&nbsp;Page</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</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> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>main.c</h1><a href="main_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 <span class="comment">/*This file has been prepared for Doxygen automatic documentation generation.*/</span>00024 <span class="preprocessor">#include &lt;ioavr.h&gt;</span>00025 <span class="preprocessor">#include &lt;inavr.h&gt;</span>00026 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>00027 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00028 <span class="preprocessor">#include "<a class="code" href="uart_8h.html">uart.h</a>"</span>00029 <span class="preprocessor">#include "<a class="code" href="sm__driver_8h.html">sm_driver.h</a>"</span>00030 <span class="preprocessor">#include "<a class="code" href="speed__cntr_8h.html">speed_cntr.h</a>"</span>00031 <a name="l00033"></a><a class="code" href="main_8c.html#a0">00033</a> <span class="keyword">struct </span><a class="code" href="structGLOBAL__FLAGS.html">GLOBAL_FLAGS</a> <a class="code" href="main_8c.html#a0">status</a> = {<a class="code" href="global_8h.html#a1">FALSE</a>, <a class="code" href="global_8h.html#a1">FALSE</a>, 0};00034 00035 <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a2">ShowHelp</a>(<span class="keywordtype">void</span>);00036 <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a3">ShowData</a>(<span class="keywordtype">int</span> position, <span class="keywordtype">int</span> acceleration, <span class="keywordtype">int</span> deceleration, <span class="keywordtype">int</span> speed, <span class="keywordtype">int</span> steps);00037 <a name="l00042"></a><a class="code" href="main_8c.html#a4">00042</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a4">Init</a>(<span class="keywordtype">void</span>)00043 {00044   <span class="comment">// Init of IO pins</span>00045   <a class="code" href="sm__driver_8c.html#a6">sm_driver_Init_IO</a>();00046   <span class="comment">// Init of uart</span>00047   <a class="code" href="uart_8c.html#a6">InitUART</a>();00048 00049   <span class="comment">// Set stepper motor driver output</span>00050   <a class="code" href="sm__driver_8h.html#a12">sm_driver_StepOutput</a>(0);00051 00052   <span class="comment">// Init of Timer/Counter1</span>00053   <a class="code" href="speed__cntr_8c.html#a2">speed_cntr_Init_Timer1</a>();00054 00055   __enable_interrupt();00056 }00057 <a name="l00062"></a><a class="code" href="main_8c.html#a5">00062</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a5">main</a>(<span class="keywordtype">void</span>)00063 {00064   <span class="comment">// Number of steps to move.</span>00065   <span class="keywordtype">int</span> steps = 1000;00066   <span class="comment">// Accelration to use.</span>00067   <span class="keywordtype">int</span> acceleration = 100;00068   <span class="comment">// Deceleration to use.</span>00069   <span class="keywordtype">int</span> deceleration = 100;00070   <span class="comment">// Speed to use.</span>00071   <span class="keywordtype">int</span> speed = 800;00072   <span class="comment">// Tells if the received string was a valid command.</span>00073   <span class="keywordtype">char</span> okCmd = <a class="code" href="global_8h.html#a1">FALSE</a>;00074 00075   <a class="code" href="main_8c.html#a4">Init</a>();00076 00077   <span class="comment">// Outputs help screen.</span>00078   <a class="code" href="uart_8h.html#a9">uart_SendString</a>(<span class="stringliteral">"\n\r"</span>);00079   <a class="code" href="main_8c.html#a2">ShowHelp</a>();00080   <a class="code" href="main_8c.html#a3">ShowData</a>(<a class="code" href="sm__driver_8c.html#a5">stepPosition</a>, acceleration, deceleration, speed, steps);00081 00082   <span class="keywordflow">while</span>(1) {00083     <span class="comment">// If a command is received, check the command and act on it.</span>00084     <span class="keywordflow">if</span>(<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>){00085       <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[0] == <span class="charliteral">'m'</span>){00086         <span class="comment">// Move with...</span>00087         <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[1] == <span class="charliteral">' '</span>){00088           <span class="comment">// ...number of steps given.</span>00089           steps = atoi((<span class="keywordtype">char</span> <span class="keyword">const</span> *)<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>+2);00090           <a class="code" href="speed__cntr_8h.html#a12">speed_cntr_Move</a>(steps, acceleration, deceleration, speed);00091           okCmd = <a class="code" href="global_8h.html#a0">TRUE</a>;00092           <a class="code" href="uart_8h.html#a9">uart_SendString</a>(<span class="stringliteral">"\n\r  "</span>);00093         }00094         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[1] == <span class="charliteral">'o'</span>){00095           <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[2] == <span class="charliteral">'v'</span>){00096             <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[3] == <span class="charliteral">'e'</span>){00097               <span class="comment">// ...all parameters given</span>00098               <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[4] == <span class="charliteral">' '</span>){00099                 <span class="keywordtype">int</span> i = 6;00100                 steps = atoi((<span class="keywordtype">char</span> <span class="keyword">const</span> *)<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>+5);00101                 <span class="keywordflow">while</span>((<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[i] != <span class="charliteral">' '</span>) &amp;&amp; (<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[i] != 13)) i++;00102                 i++;00103                 acceleration = atoi((<span class="keywordtype">char</span> <span class="keyword">const</span> *)<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>+i);00104                 <span class="keywordflow">while</span>((<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[i] != <span class="charliteral">' '</span>) &amp;&amp; (<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[i] != 13)) i++;00105                 i++;00106                 deceleration = atoi((<span class="keywordtype">char</span> <span class="keyword">const</span> *)<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>+i);00107                 <span class="keywordflow">while</span>((<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[i] != <span class="charliteral">' '</span>) &amp;&amp; (<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>[i] != 13)) i++;00108                 i++;00109                 speed = atoi((<span class="keywordtype">char</span> <span class="keyword">const</span> *)<a class="code" href="uart_8c.html#a1">UART_RxBuffer</a>+i);00110                 <a class="code" href="speed__cntr_8h.html#a12">speed_cntr_Move</a>(steps, acceleration, deceleration, speed);

⌨️ 快捷键说明

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