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

📄 ds1631_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: ds1631.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>ds1631.c</h1><a href="ds1631_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file ds1631.c \brief Dallas DS1631 Temperature Sensor Driver Library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'ds1631.c'</span>00005 <span class="comment">// Title        : Dallas DS1631 Temperature Sensor 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 &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="timer_8h.html">timer.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="ds1631_8h.html">ds1631.h</a>"</span>00029 00030 <span class="comment">// global variables</span>00031 00032 <span class="comment">// Functions</span><a name="l00033"></a><a class="code" href="ds1631_8h.html#a16">00033</a> u08 <a class="code" href="ds1631_8c.html#a0">ds1631Init</a>(u08 i2cAddr)00034 {00035     u08 chip_ok;00036     <span class="comment">// issue a reset</span>00037     <span class="keywordflow">if</span>(<a class="code" href="ds1631_8c.html#a1">ds1631Reset</a>(i2cAddr) == I2C_OK)00038         chip_ok = TRUE;00039     <span class="keywordflow">else</span>00040         chip_ok = FALSE;00041     <span class="comment">// set a default configuration</span>00042     <span class="comment">// (1-shot mode, T_OUT active high, and 12-bit conversion)</span>00043     <a class="code" href="ds1631_8c.html#a2">ds1631SetConfig</a>(i2cAddr,00044         DS1631_CONFIG_1SHOT | DS1631_CONFIG_POL |00045         DS1631_CONFIG_R0 | DS1631_CONFIG_R1);00046     <span class="keywordflow">return</span> chip_ok;00047 }00048 <a name="l00049"></a><a class="code" href="ds1631_8h.html#a17">00049</a> u08 <a class="code" href="ds1631_8c.html#a1">ds1631Reset</a>(u08 i2cAddr)00050 {00051     u08 buffer[1];00052     <span class="comment">// return the DS1631 to power-on reset defaults</span>00053     buffer[0] = <a class="code" href="ds1631_8h.html#a7">DS1631_CMD_SWPOR</a>;00054     <span class="keywordflow">return</span> <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer);00055 }00056 <a name="l00057"></a><a class="code" href="ds1631_8h.html#a18">00057</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a2">ds1631SetConfig</a>(u08 i2cAddr, u08 config)00058 {00059     u08 buffer[2];00060     <span class="comment">// write the DS1631 configuration byte</span>00061     buffer[0] = <a class="code" href="ds1631_8h.html#a6">DS1631_CMD_ACCESSCONFIG</a>;00062     buffer[1] = config;00063     <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 2, buffer);00064 }00065 <a name="l00066"></a><a class="code" href="ds1631_8h.html#a19">00066</a> u08 <a class="code" href="ds1631_8c.html#a3">ds1631GetConfig</a>(u08 i2cAddr)00067 {00068     u08 buffer[1];00069     <span class="comment">// write the DS1631 configuration byte</span>00070     buffer[0] = <a class="code" href="ds1631_8h.html#a6">DS1631_CMD_ACCESSCONFIG</a>;00071     <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 2, buffer);00072     <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer);00073     <span class="keywordflow">return</span> buffer[0];00074 }00075 <a name="l00076"></a><a class="code" href="ds1631_8h.html#a20">00076</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a4">ds1631StartConvert</a>(u08 i2cAddr)00077 {00078     u08 buffer[1];00079     <span class="comment">// send the DS1631 Start Convert command</span>00080     buffer[0] = <a class="code" href="ds1631_8h.html#a1">DS1631_CMD_STARTCONV</a>;00081     <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer);00082 }00083 <a name="l00084"></a><a class="code" href="ds1631_8h.html#a21">00084</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a5">ds1631StopConvert</a>(u08 i2cAddr)00085 {00086     u08 buffer[1];00087     <span class="comment">// send the DS1631 Stop Convert command</span>00088     buffer[0] = <a class="code" href="ds1631_8h.html#a2">DS1631_CMD_STOPCONV</a>;00089     <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer);00090 }00091 <a name="l00092"></a><a class="code" href="ds1631_8h.html#a22">00092</a> s16 <a class="code" href="ds1631_8c.html#a6">ds1631ReadTemp</a>(u08 i2cAddr)00093 {00094     <span class="comment">// read the Temperature register and return the result</span>00095     <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a3">DS1631_CMD_READTEMP</a>);00096 }00097 <a name="l00098"></a><a class="code" href="ds1631_8h.html#a23">00098</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a7">ds1631SetTH</a>(u08 i2cAddr, s16 value)00099 {00100     <span class="comment">// write the TH register</span>00101     ds1631WriteTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a4">DS1631_CMD_ACCESSTH</a>, value);00102 }00103 <a name="l00104"></a><a class="code" href="ds1631_8h.html#a24">00104</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8c.html#a8">ds1631SetTL</a>(u08 i2cAddr, s16 value)00105 {00106     <span class="comment">// write the TL register</span>00107     ds1631WriteTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a5">DS1631_CMD_ACCESSTL</a>, value);00108 }00109 <a name="l00110"></a><a class="code" href="ds1631_8h.html#a25">00110</a> s16 <a class="code" href="ds1631_8c.html#a9">ds1631GetTH</a>(u08 i2cAddr)00111 {00112     <span class="comment">// read the TH register and return the result</span>00113     <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a4">DS1631_CMD_ACCESSTH</a>);00114 }00115 <a name="l00116"></a><a class="code" href="ds1631_8h.html#a26">00116</a> s16 <a class="code" href="ds1631_8c.html#a10">ds1631GetTL</a>(u08 i2cAddr)00117 {00118     <span class="comment">// read the TL register and return the result</span>00119     <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, <a class="code" href="ds1631_8h.html#a5">DS1631_CMD_ACCESSTL</a>);00120 }00121 00122 00123 s16 ds1631ReadTempReg(u08 i2cAddr, u08 cmd)00124 {00125     u08 buffer[2];00126     s16 T;00127 00128     <span class="comment">// read the temperature value from the requested register</span>00129     <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, &amp;cmd);00130     <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer);00131     <span class="comment">// pack bytes</span>00132     T = (s16)((buffer[0]&lt;&lt;8) | buffer[1]);00133     <span class="comment">// return result</span>00134     <span class="keywordflow">return</span> T;00135 }00136 00137 <span class="keywordtype">void</span> ds1631WriteTempReg(u08 i2cAddr, u08 cmd, s16 value)00138 {00139     u08 buffer[3];00140 00141     <span class="comment">// write the requested register with a temperature value</span>00142     buffer[0] = cmd;00143     buffer[1] = value&gt;&gt;8;00144     buffer[2] = value;00145     <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 3, buffer);00146 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 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 + -