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

📄 lis3l02_8c-source.html

📁 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: lis3l02.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><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="dirs.html">Directories</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>lis3l02.c</h1><a href="lis3l02_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file lis3l02.c \brief ST LIS3L02 3-axis I2C Accelerometer Library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'lis3l02.c'</span>00005 <span class="comment">// Title        : ST LIS3L02 3-axis I2C Accelerometer Library</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2004</span>00007 <span class="comment">// Created      : 2004.10.23</span>00008 <span class="comment">// Revised      : 2004.12.14</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 &lt;avr/io.h&gt;</span>00023 <span class="preprocessor">#include &lt;avr/interrupt.h&gt;</span>00024 00025 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00026 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span>00027 <span class="preprocessor">#include "<a class="code" href="lis3l02_8h.html">lis3l02.h</a>"</span>00028 00029 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>00030 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>00031 00032 <span class="comment">// global variables</span>00033 00034 <span class="comment">// Functions</span><a name="l00035"></a><a class="code" href="lis3l02_8h.html#a58">00035</a> u08 <a class="code" href="lis3l02_8c.html#a0">lis3l02Init</a>(<span class="keywordtype">void</span>)00036 {00037     <span class="comment">// reset LIS3L02 chip</span>00038     <span class="keywordflow">return</span> <a class="code" href="lis3l02_8c.html#a1">lis3l02Reset</a>();00039 }00040 <a name="l00041"></a><a class="code" href="lis3l02_8h.html#a59">00041</a> u08 <a class="code" href="lis3l02_8c.html#a1">lis3l02Reset</a>(<span class="keywordtype">void</span>)00042 {00043     <span class="comment">// turn on device and enable X,Y,Z</span>00044     <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(<a class="code" href="lis3l02_8h.html#a7">LIS3L02_REG_CTRLREG1</a>,00045         <a class="code" href="lis3l02_8h.html#a22">LIS3L02_CTRLREG1_XEN</a> |00046         <a class="code" href="lis3l02_8h.html#a23">LIS3L02_CTRLREG1_YEN</a> |00047         <a class="code" href="lis3l02_8h.html#a24">LIS3L02_CTRLREG1_ZEN</a> |00048         <a class="code" href="lis3l02_8h.html#a28">LIS3L02_CTRLREG1_PD0</a>);00049 00050     <span class="comment">// scale and justification options</span>00051     <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(<a class="code" href="lis3l02_8h.html#a8">LIS3L02_REG_CTRLREG2</a>,00052         <a class="code" href="lis3l02_8h.html#a34">LIS3L02_CTRLREG2_BOOT</a> | 00053         <a class="code" href="lis3l02_8h.html#a30">LIS3L02_CTRLREG2_DAS</a> );00054 00055     <span class="keywordflow">return</span> 0;00056 }00057 <a name="l00058"></a><a class="code" href="lis3l02_8h.html#a60">00058</a> u08 <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(u08 reg)00059 {00060     u08 data;00061     u08 i2cStat;00062 00063     <span class="comment">// set register</span>00064     i2cStat = <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 1, &amp;reg);00065     <span class="keywordflow">if</span>(i2cStat == I2C_ERROR_NODEV)00066     {00067         rprintf(<span class="stringliteral">"No I2C Device\r\n"</span>);00068         <span class="keywordflow">return</span> i2cStat;00069     }00070     <span class="comment">// read register</span>00071     i2cStat = <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 1, &amp;data);00072 00073     <span class="comment">//rprintf("READ: Reg=0x%x  Data=0x%x\r\n", reg, data);</span>00074 00075     <span class="keywordflow">return</span> data;00076 }00077 <a name="l00078"></a><a class="code" href="lis3l02_8h.html#a61">00078</a> u08 <a class="code" href="lis3l02_8c.html#a3">lis3l02WriteReg</a>(u08 reg, u08 data)00079 {00080     u08 packet[2];00081     u08 i2cStat;00082     00083     <span class="comment">// prepare packet</span>00084     packet[0] = reg;00085     packet[1] = data;00086     <span class="comment">// write register</span>00087     i2cStat = <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(<a class="code" href="lis3l02_8h.html#a0">LIS3L02_I2C_ADDR</a>, 2, packet);00088     <span class="keywordflow">if</span>(i2cStat == I2C_ERROR_NODEV)00089     {00090         rprintf(<span class="stringliteral">"No I2C Device\r\n"</span>);00091         <span class="keywordflow">return</span> i2cStat;00092     }00093 00094     <span class="comment">//rprintf("WRITE: Reg=0x%x  Data=0x%x\r\n", reg, data);</span>00095 00096     <span class="keywordflow">return</span> (i2cStat == I2C_OK);00097 }00098 <a name="l00099"></a><a class="code" href="lis3l02_8h.html#a62">00099</a> s16 <a class="code" href="lis3l02_8c.html#a4">lis3l02GetAccel</a>(u08 chxyz)00100 {00101     s16 value;00102     00103     value  = <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(<a class="code" href="lis3l02_8h.html#a13">LIS3L02_REG_OUTXL</a> + (chxyz&lt;&lt;1));00104     value |= <a class="code" href="lis3l02_8c.html#a2">lis3l02ReadReg</a>(<a class="code" href="lis3l02_8h.html#a14">LIS3L02_REG_OUTXH</a> + (chxyz&lt;&lt;1))&lt;&lt;8;00105 00106     <span class="keywordflow">return</span> value;00107 }00108 00109 00110 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>

⌨️ 快捷键说明

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