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

📄 servo_8h-source.html

📁 ATMEL的AVR单片机库文件
💻 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: servo.h Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><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="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>servo.h</h1><a href="servo_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file servo.h \brief Interrupt-driven RC Servo function library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'servo.h'</span>00005 <span class="comment">// Title        : Interrupt-driven RC Servo function library</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2002</span>00007 <span class="comment">// Created      : 7/31/2002</span>00008 <span class="comment">// Revised      : 8/02/2002</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">// NOTE: you need the latest version (3.2+) of the AVR-GCC compiler to use this</span>00014 <span class="comment">//  function library.  Download it from http://www.avrfreaks.net/AVRGCC</span>00015 <span class="comment">//</span>00016 <span class="comment">// Description : This code allows you to drive up to 8 RC servos from any</span>00017 <span class="comment">//      combination of ports and pins on the AVR processor. Using interrupts,</span>00018 <span class="comment">//      this code continuously sends control signals to the servo to maintain</span>00019 <span class="comment">//      position even while your code is doing other work.</span>00020 <span class="comment">//</span>00021 <span class="comment">//      The servoInit and servoOff effectively turn on and turn off servo</span>00022 <span class="comment">//      control.  When you run ServoInit, it automatically assigns each</span>00023 <span class="comment">//      "channel" of servo control to be output on the SERVO_DEFAULT_PORT.</span>00024 <span class="comment">//      One "channel" of servo control can control one servo and must be</span>00025 <span class="comment">//      assigned single I/O pin for output.</span>00026 <span class="comment">//</span>00027 <span class="comment">//      If you're using all eight channels (SERVO_NUM_CHANNELS = 8), then</span>00028 <span class="comment">//      then by default the code will use SERVO_DEFAULT_PORT pins 0-7.</span>00029 <span class="comment">//      If you're only using four channels, then pins 0-3 will be used by</span>00030 <span class="comment">//      default.</span>00031 <span class="comment">//</span>00032 <span class="comment">//      The command servoSetChannelIO(channel, port, pin) allows you to</span>00033 <span class="comment">//      reassign the output of any channel to any port and I/O pin you</span>00034 <span class="comment">//      choose.  For exampe, if you have an RC servo connected to PORTC, pin 6,</span>00035 <span class="comment">//      and you wish to use channel 2 to control it, use:</span>00036 <span class="comment">//</span>00037 <span class="comment">//      servoSerChannelIO( 2, _SFR_IO_ADDR(PORTC), 6)</span>00038 <span class="comment">//</span>00039 <span class="comment">//      (NOTE: you must include the "_SRF_IO_ADDR()" part around your port)</span>00040 <span class="comment">//</span>00041 <span class="comment">//      The servoSetPostion and servoGetPosition commands allow you to command</span>00042 <span class="comment">//      a given servo to your desired position.  The position you request must</span>00043 <span class="comment">//      lie between the SERVO_MIN and SERVO_MAX limit you defined.</span>00044 <span class="comment">//</span>00045 <span class="comment">// This code is distributed under the GNU Public License</span>00046 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>00047 <span class="comment">//</span>00048 <span class="comment">//*****************************************************************************</span>00049 00050 <span class="preprocessor">#ifndef SERVO_H</span>00051 <span class="preprocessor"></span><span class="preprocessor">#define SERVO_H</span>00052 <span class="preprocessor"></span>00053 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00054 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>00055 00056 <span class="comment">// include configuration</span>00057 <span class="preprocessor">#include "<a class="code" href="servoconf_8h.html">servoconf.h</a>"</span>00058 00059 <span class="keyword">typedef</span> <span class="keyword">struct </span>struct_ServoChannel00060 {   00061     <span class="comment">// hardware I/O port and pin for this channel</span>00062     u08 port;00063     u08 pin;00064     <span class="comment">// PWM duty setting which corresponds to servo position</span>00065     u16 duty;00066 } ServoChannelType;00067 00068 <span class="comment">// functions</span>00069 00070 <span class="comment">// initializes servo system</span>00071 <span class="comment">//      You must run this to begin servo control</span>00072 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a4">servoInit</a>(<span class="keywordtype">void</span>);00073 00074 <span class="comment">// turns off servo system</span>00075 <span class="comment">//      This stops controlling the servos and</span>00076 <span class="comment">//      returns control of the SERVOPORT to your code</span>00077 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a5">servoOff</a>(<span class="keywordtype">void</span>);00078 00079 <span class="comment">// set the port and I/O pin you wish to use for a given channel</span>00080 <span class="comment">//      If you do not assign a port and I/O pin for a channel (ie. you don't</span>00081 <span class="comment">//      use this command) then all output will be done through the</span>00082 <span class="comment">//      SERVO_DEFAULT_PORT.  See above definition of SERVO_DEFAULT_PORT.</span>00083 <span class="keywordtype">void</span> <a class="code" href="servo_8h.html#a3">servoSetChannelIO</a>(u08 channel, u08 port, u08 pin);00084 00085 <span class="comment">// set and get servo position on a given channel </span>00086 <span class="comment">//      servoSetPosition() commands the servo on &lt;channel&gt; to the position you</span>00087 <span class="comment">//          desire.  The position input must lie between 0 and POSITION_MAX and</span>00088 <span class="comment">//          will be automatically scaled to raw positions between SERVO_MIN and</span>00089 <span class="comment">//          SERVO_MAX</span>00090 <span class="comment">//      servoGetPosition() returns the most recently set postition of the</span>00091 <span class="comment">//          servo on &lt;channel&gt;.  The return value will be scaled 0-&gt;POSITION_MAX</span>00092 <span class="keywordtype">void</span> <a class="code" href="servo_8h.html#a4">servoSetPosition</a>(u08 channel, u08 position);00093 u08 <a class="code" href="servo_8h.html#a5">servoGetPosition</a>(u08 channel);00094 00095 <span class="comment">// set and get raw servo position on a given channel</span>00096 <span class="comment">//      Works like non-raw commands but position is not scaled.  Position must</span>00097 <span class="comment">//      be between SERVO_MIN and SERVO_MAX</span>00098 <span class="keywordtype">void</span> <a class="code" href="servo_8h.html#a6">servoSetPositionRaw</a>(u08 channel, u16 position);00099 u16 <a class="code" href="servo_8h.html#a7">servoGetPositionRaw</a>(u08 channel);00100 00101 <span class="comment">// servo interrupt service routine</span>00102 <span class="keywordtype">void</span> servoService(<span class="keywordtype">void</span>);00103 00104 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 15 03:50:22 2004 for Procyon AVRlib by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>

⌨️ 快捷键说明

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