📄 ads7828_8c-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: ads7828.c 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>ads7828.c</h1><a href="ads7828_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file ads7828.c \brief TI ADS7828 12-bit 8ch A/D Converter Driver Library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'ads7828.c'</span>00005 <span class="comment">// Title : TI ADS7828 12-bit 8ch A/D Converter Driver Library</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span>00007 <span class="comment">// Created : 2004.02.10</span>00008 <span class="comment">// Revised : 2004.02.19</span>00009 <span class="comment">// Version : 0.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">// NOTE: This code is currently below version 1.0, and therefore is considered</span>00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>00016 <span class="comment">//</span>00017 <span class="comment">// This code is distributed under the GNU Public License</span>00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00019 <span class="comment">//</span>00020 <span class="comment">//*****************************************************************************</span>00021 00022 <span class="preprocessor">#include <avr/io.h></span>00023 <span class="preprocessor">#include <avr/signal.h></span>00024 <span class="preprocessor">#include <avr/interrupt.h></span>00025 00026 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00027 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span>00028 <span class="preprocessor">#include "<a class="code" href="ads7828_8h.html">ads7828.h</a>"</span>00029 00030 <span class="comment">// global variables</span>00031 u08 Ads7282RefMode;00032 00033 <span class="comment">// Functions</span><a name="l00034"></a><a class="code" href="ads7828_8h.html#a19">00034</a> u08 <a class="code" href="ads7828_8h.html#a19">ads7828Init</a>(u08 i2cAddr)00035 {00036 u08 channel = 0x80;00037 00038 <span class="comment">// setup default A/D voltage reference</span>00039 <a class="code" href="ads7828_8h.html#a20">ads7828SetReference</a>(0);00040 00041 <span class="comment">// issue a convserion to test chip presence</span>00042 <span class="comment">// return TRUE if chip detected</span>00043 <span class="comment">// return FALSE if chip does not respond</span>00044 <span class="keywordflow">return</span> (<a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, &channel) == I2C_OK);00045 }00046 <a name="l00047"></a><a class="code" href="ads7828_8h.html#a21">00047</a> u16 <a class="code" href="ads7828_8h.html#a21">ads7828Convert</a>(u08 i2cAddr, u08 channel)00048 {00049 <span class="comment">// re-order channel bits for</span>00050 <span class="comment">// logical single-ended channel selection</span>00051 <span class="comment">// channel bit0 -> C2</span>00052 <span class="comment">// channel bit1 -> C0</span>00053 <span class="comment">// channel bit2 -> C1</span>00054 channel = (((channel>>1) | (channel&0x01)<<2)<<4) | ADS7828_CMD_SD;00055 <span class="comment">// do conversion</span>00056 <span class="keywordflow">return</span> <a class="code" href="ads7828_8h.html#a23">ads7828ConvertRaw</a>(i2cAddr, channel);00057 }00058 <a name="l00059"></a><a class="code" href="ads7828_8h.html#a22">00059</a> u16 <a class="code" href="ads7828_8h.html#a22">ads7828ConvertDiff</a>(u08 i2cAddr, u08 channel)00060 {00061 <span class="comment">// clear single-ended channel bit</span>00062 channel = (channel&0x07)<<4;00063 <span class="comment">// do conversion</span>00064 <span class="keywordflow">return</span> <a class="code" href="ads7828_8h.html#a23">ads7828ConvertRaw</a>(i2cAddr, channel);00065 }00066 <a name="l00067"></a><a class="code" href="ads7828_8h.html#a23">00067</a> u16 <a class="code" href="ads7828_8h.html#a23">ads7828ConvertRaw</a>(u08 i2cAddr, u08 channel)00068 {00069 u08 buffer[2];00070 <span class="comment">// combine raw channel and reference bits</span>00071 channel &= 0xF0;00072 channel |= Ads7282RefMode;00073 <span class="comment">// start conversion on requested channel</span>00074 <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, &channel);00075 <span class="comment">// retrieve conversion result</span>00076 <a class="code" href="i2c_8h.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer);00077 <span class="comment">// pack bytes and return result</span>00078 <span class="keywordflow">return</span> ((buffer[0]<<8) | buffer[1]);00079 }00080 <a name="l00081"></a><a class="code" href="ads7828_8h.html#a20">00081</a> <span class="keywordtype">void</span> <a class="code" href="ads7828_8h.html#a20">ads7828SetReference</a>(u08 ref)00082 {00083 <span class="keywordflow">if</span>(ref)00084 {00085 <span class="comment">// use internal reference</span>00086 Ads7282RefMode = ADS7828_CMD_PDMODE2;00087 }00088 <span class="keywordflow">else</span>00089 {00090 <span class="comment">// use external reference</span>00091 Ads7282RefMode = ADS7828_CMD_PDMODE0;00092 }00093 }</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 + -