📄 a2d_8h-source.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: a2d.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 Page</a> | <a class="qindex" href="modules.html">Modules</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></div><h1>a2d.h</h1><a href="a2d_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file a2d.h \brief Analog-to-Digital converter function library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'a2d.h'</span>00005 <span class="comment">// Title : Analog-to-digital converter functions</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002</span>00007 <span class="comment">// Created : 4/08/2002</span>00008 <span class="comment">// Revised : 4/30/2002</span>00009 <span class="comment">// Version : 1.1</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">// This code is distributed under the GNU Public License</span>00014 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00015 <span class="comment">//</span>00016 <span class="comment">//*****************************************************************************</span>00017 00018 <span class="preprocessor">#ifndef A2D_H</span>00019 <span class="preprocessor"></span><span class="preprocessor">#define A2D_H</span>00020 <span class="preprocessor"></span>00021 <span class="comment">// defines</span>00022 00023 <span class="comment">// A2D clock prescaler select</span>00024 <span class="comment">// *selects how much the CPU clock frequency is divided</span>00025 <span class="comment">// to create the A2D clock frequency</span>00026 <span class="comment">// *lower division ratios make conversion go faster</span>00027 <span class="comment">// *higher division ratios make conversions more accurate</span><a name="l00028"></a><a class="code" href="a2d_8h.html#a0">00028</a> <span class="preprocessor">#define ADC_PRESCALE_DIV2 0x00 </span><span class="comment">///< 0x01,0x00 -> CPU clk/2</span><a name="l00029"></a><a class="code" href="a2d_8h.html#a1">00029</a> <span class="comment"></span>#define ADC_PRESCALE_DIV4 0x02 <span class="comment">///< 0x02 -> CPU clk/4</span><a name="l00030"></a><a class="code" href="a2d_8h.html#a2">00030</a> <span class="comment"></span>#define ADC_PRESCALE_DIV8 0x03 <span class="comment">///< 0x03 -> CPU clk/8</span><a name="l00031"></a><a class="code" href="a2d_8h.html#a3">00031</a> <span class="comment"></span>#define ADC_PRESCALE_DIV16 0x04 <span class="comment">///< 0x04 -> CPU clk/16</span><a name="l00032"></a><a class="code" href="a2d_8h.html#a4">00032</a> <span class="comment"></span>#define ADC_PRESCALE_DIV32 0x05 <span class="comment">///< 0x05 -> CPU clk/32</span><a name="l00033"></a><a class="code" href="a2d_8h.html#a5">00033</a> <span class="comment"></span>#define ADC_PRESCALE_DIV64 0x06 <span class="comment">///< 0x06 -> CPU clk/64</span><a name="l00034"></a><a class="code" href="a2d_8h.html#a6">00034</a> <span class="comment"></span>#define ADC_PRESCALE_DIV128 0x07 <span class="comment">///< 0x07 -> CPU clk/128</span>00035 <span class="comment"></span>// default value00036 <span class="preprocessor">#define ADC_PRESCALE ADC_PRESCALE_DIV64</span>00037 <span class="preprocessor"></span><span class="comment">// do not change the mask value</span>00038 <span class="preprocessor">#define ADC_PRESCALE_MASK 0x07</span>00039 <span class="preprocessor"></span>00040 <span class="comment">// A2D voltage reference select</span>00041 <span class="comment">// *this determines what is used as the</span>00042 <span class="comment">// full-scale voltage point for A2D conversions</span><a name="l00043"></a><a class="code" href="a2d_8h.html#a9">00043</a> <span class="preprocessor">#define ADC_REFERENCE_AREF 0x00 </span><span class="comment">///< 0x00 -> AREF pin, internal VREF turned off</span><a name="l00044"></a><a class="code" href="a2d_8h.html#a10">00044</a> <span class="comment"></span>#define ADC_REFERENCE_AVCC 0x01 <span class="comment">///< 0x01 -> AVCC pin, internal VREF turned off</span><a name="l00045"></a><a class="code" href="a2d_8h.html#a11">00045</a> <span class="comment"></span>#define ADC_REFERENCE_RSVD 0x02 <span class="comment">///< 0x02 -> Reserved</span><a name="l00046"></a><a class="code" href="a2d_8h.html#a12">00046</a> <span class="comment"></span>#define ADC_REFERENCE_256V 0x03 <span class="comment">///< 0x03 -> Internal 2.56V VREF</span>00047 <span class="comment"></span>// default value00048 <span class="preprocessor">#define ADC_REFERENCE ADC_REFERENCE_AVCC</span>00049 <span class="preprocessor"></span><span class="comment">// do not change the mask value</span>00050 <span class="preprocessor">#define ADC_REFERENCE_MASK 0xC0</span>00051 <span class="preprocessor"></span>00052 <span class="comment">// bit mask for A2D channel multiplexer</span>00053 <span class="preprocessor">#define ADC_MUX_MASK 0x1F</span>00054 <span class="preprocessor"></span>00055 <span class="comment">// channel defines (for reference and use in code)</span>00056 <span class="comment">// these channels supported by all AVRs with A2D</span>00057 <span class="preprocessor">#define ADC_CH_ADC0 0x00</span>00058 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_ADC1 0x01</span>00059 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_ADC2 0x02</span>00060 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_ADC3 0x03</span>00061 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_ADC4 0x04</span>00062 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_ADC5 0x05</span>00063 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_ADC6 0x06</span>00064 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_ADC7 0x07</span><a name="l00065"></a><a class="code" href="a2d_8h.html#a24">00065</a> <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_122V 0x1E </span><span class="comment">///< 1.22V voltage reference</span><a name="l00066"></a><a class="code" href="a2d_8h.html#a25">00066</a> <span class="comment"></span>#define ADC_CH_AGND 0x1F <span class="comment">///< AGND</span>00067 <span class="comment"></span>// these channels supported only in ATmega12800068 <span class="comment">// differential with gain</span>00069 <span class="preprocessor">#define ADC_CH_0_0_DIFF10X 0x08</span>00070 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_1_0_DIFF10X 0x09</span>00071 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_0_0_DIFF200X 0x0A</span>00072 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_1_0_DIFF200X 0x0B</span>00073 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_2_2_DIFF10X 0x0C</span>00074 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_3_2_DIFF10X 0x0D</span>00075 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_2_2_DIFF200X 0x0E</span>00076 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_3_2_DIFF200X 0x0F</span>00077 <span class="preprocessor"></span><span class="comment">// differential</span>00078 <span class="preprocessor">#define ADC_CH_0_1_DIFF1X 0x10</span>00079 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_1_1_DIFF1X 0x11</span>00080 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_2_1_DIFF1X 0x12</span>00081 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_3_1_DIFF1X 0x13</span>00082 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_4_1_DIFF1X 0x14</span>00083 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_5_1_DIFF1X 0x15</span>00084 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_6_1_DIFF1X 0x16</span>00085 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_7_1_DIFF1X 0x17</span>00086 <span class="preprocessor"></span>00087 <span class="preprocessor">#define ADC_CH_0_2_DIFF1X 0x18</span>00088 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_1_2_DIFF1X 0x19</span>00089 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_2_2_DIFF1X 0x1A</span>00090 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_3_2_DIFF1X 0x1B</span>00091 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_4_2_DIFF1X 0x1C</span>00092 <span class="preprocessor"></span><span class="preprocessor">#define ADC_CH_5_2_DIFF1X 0x1D</span>00093 <span class="preprocessor"></span>00094 <span class="comment">// compatibility for new Mega processors</span>00095 <span class="comment">// ADCSR hack apparently no longer necessary in new AVR-GCC</span>00096 <span class="preprocessor">#ifdef ADCSRA</span>00097 <span class="preprocessor"></span><span class="preprocessor">#ifndef ADCSR</span>00098 <span class="preprocessor"></span><span class="preprocessor"> #define ADCSR ADCSRA</span>00099 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00100 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00101 <span class="preprocessor"></span><span class="preprocessor">#ifdef ADATE</span>00102 <span class="preprocessor"></span><span class="preprocessor"> #define ADFR ADATE</span>00103 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00104 <span class="preprocessor"></span>00105 <span class="comment">// function prototypes</span>00106 <span class="comment"></span>00107 <span class="comment">//! Initializes the A/D converter</span>00108 <span class="comment"></span><span class="comment">// (turns ADC on and prepares it for use)</span>00109 <span class="keywordtype">void</span> <a class="code" href="a2d_8c.html#a1">a2dInit</a>(<span class="keywordtype">void</span>);00110 <span class="comment"></span>00111 <span class="comment">//! Turn off A/D converter</span>00112 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="a2d_8c.html#a2">a2dOff</a>(<span class="keywordtype">void</span>);00113 <span class="comment"></span>00114 <span class="comment">//! sets the division ratio of the A/D converter clock</span>00115 <span class="comment"></span><span class="comment">// this function is automatically called from a2dInit()</span>00116 <span class="comment">// with a default value</span>00117 <span class="keywordtype">void</span> <a class="code" href="a2d_8h.html#a50">a2dSetPrescaler</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> prescale);00118 <span class="comment"></span>00119 <span class="comment">//! configures which voltage reference the A/D converter uses</span>00120 <span class="comment"></span><span class="comment">// this function is automatically called from a2dInit()</span>00121 <span class="comment">// with a default value</span>00122 <span class="keywordtype">void</span> <a class="code" href="a2d_8h.html#a51">a2dSetReference</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ref);00123 <span class="comment"></span>00124 <span class="comment">//! sets the a2d input channel</span>00125 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="a2d_8h.html#a52">a2dSetChannel</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ch);00126 <span class="comment"></span>00127 <span class="comment">//! start a conversion on the current a2d input channel</span>00128 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="a2d_8c.html#a6">a2dStartConvert</a>(<span class="keywordtype">void</span>);00129 <span class="comment"></span>00130 <span class="comment">//! return TRUE if conversion is complete</span>00131 <span class="comment"></span>u08 <a class="code" href="a2d_8c.html#a7">a2dIsComplete</a>(<span class="keywordtype">void</span>);00132 <span class="comment"></span>00133 <span class="comment">//! starts a conversion on A/D channel# ch,</span>00134 <span class="comment"></span><span class="comment">// returns the 10-bit value of the conversion when it is finished</span>00135 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="a2d_8h.html#a55">a2dConvert10bit</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ch);00136 <span class="comment"></span>00137 <span class="comment">//! starts a conversion on A/D channel# ch,</span>00138 <span class="comment"></span><span class="comment">// returns the 8-bit value of the conversion when it is finished</span>00139 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="a2d_8h.html#a56">a2dConvert8bit</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ch);00140 00141 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 15 03:50:21 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 + -