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

📄 ds1631_8c-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: ds1631.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&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>ds1631.c</h1><a href="ds1631_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>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/signal.h&gt;</span>00024 <span class="preprocessor">#include &lt;avr/interrupt.h&gt;</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="timer_8h.html">timer.h</a>"</span>00028 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span>00029 <span class="preprocessor">#include "<a class="code" href="ds1631_8h.html">ds1631.h</a>"</span>00030 00031 <span class="comment">// global variables</span>00032 00033 <span class="comment">// Functions</span><a name="l00034"></a><a class="code" href="ds1631_8h.html#a16">00034</a> u08 <a class="code" href="ds1631_8h.html#a16">ds1631Init</a>(u08 i2cAddr)00035 {00036     u08 chip_ok;00037     <span class="comment">// issue a reset</span>00038     <span class="keywordflow">if</span>(<a class="code" href="ds1631_8h.html#a17">ds1631Reset</a>(i2cAddr) == I2C_OK)00039         chip_ok = TRUE;00040     <span class="keywordflow">else</span>00041         chip_ok = FALSE;00042     <span class="comment">// set a default configuration</span>00043     <span class="comment">// (1-shot mode, T_OUT active high, and 12-bit conversion)</span>00044     <a class="code" href="ds1631_8h.html#a18">ds1631SetConfig</a>(i2cAddr,00045         DS1631_CONFIG_1SHOT | DS1631_CONFIG_POL |00046         DS1631_CONFIG_R0 | DS1631_CONFIG_R1);00047     <span class="keywordflow">return</span> chip_ok;00048 }00049 <a name="l00050"></a><a class="code" href="ds1631_8h.html#a17">00050</a> u08 <a class="code" href="ds1631_8h.html#a17">ds1631Reset</a>(u08 i2cAddr)00051 {00052     u08 buffer[1];00053     <span class="comment">// return the DS1631 to power-on reset defaults</span>00054     buffer[0] = DS1631_CMD_SWPOR;00055     <span class="keywordflow">return</span> <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer);00056 }00057 <a name="l00058"></a><a class="code" href="ds1631_8h.html#a18">00058</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8h.html#a18">ds1631SetConfig</a>(u08 i2cAddr, u08 config)00059 {00060     u08 buffer[2];00061     <span class="comment">// write the DS1631 configuration byte</span>00062     buffer[0] = DS1631_CMD_ACCESSCONFIG;00063     buffer[1] = config;00064     <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 2, buffer);00065 }00066 <a name="l00067"></a><a class="code" href="ds1631_8h.html#a19">00067</a> u08 <a class="code" href="ds1631_8h.html#a19">ds1631GetConfig</a>(u08 i2cAddr)00068 {00069     u08 buffer[1];00070     <span class="comment">// write the DS1631 configuration byte</span>00071     buffer[0] = DS1631_CMD_ACCESSCONFIG;00072     <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 2, buffer);00073     <a class="code" href="i2c_8h.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer);00074     <span class="keywordflow">return</span> buffer[0];00075 }00076 <a name="l00077"></a><a class="code" href="ds1631_8h.html#a20">00077</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8h.html#a20">ds1631StartConvert</a>(u08 i2cAddr)00078 {00079     u08 buffer[1];00080     <span class="comment">// send the DS1631 Start Convert command</span>00081     buffer[0] = DS1631_CMD_STARTCONV;00082     <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer);00083 }00084 <a name="l00085"></a><a class="code" href="ds1631_8h.html#a21">00085</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8h.html#a21">ds1631StopConvert</a>(u08 i2cAddr)00086 {00087     u08 buffer[1];00088     <span class="comment">// send the DS1631 Stop Convert command</span>00089     buffer[0] = DS1631_CMD_STOPCONV;00090     <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, buffer);00091 }00092 <a name="l00093"></a><a class="code" href="ds1631_8h.html#a22">00093</a> s16 <a class="code" href="ds1631_8h.html#a22">ds1631ReadTemp</a>(u08 i2cAddr)00094 {00095     <span class="comment">// read the Temperature register and return the result</span>00096     <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, DS1631_CMD_READTEMP);00097 }00098 <a name="l00099"></a><a class="code" href="ds1631_8h.html#a23">00099</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8h.html#a23">ds1631SetTH</a>(u08 i2cAddr, s16 value)00100 {00101     <span class="comment">// write the TH register</span>00102     ds1631WriteTempReg(i2cAddr, DS1631_CMD_ACCESSTH, value);00103 }00104 <a name="l00105"></a><a class="code" href="ds1631_8h.html#a24">00105</a> <span class="keywordtype">void</span> <a class="code" href="ds1631_8h.html#a24">ds1631SetTL</a>(u08 i2cAddr, s16 value)00106 {00107     <span class="comment">// write the TL register</span>00108     ds1631WriteTempReg(i2cAddr, DS1631_CMD_ACCESSTL, value);00109 }00110 <a name="l00111"></a><a class="code" href="ds1631_8h.html#a25">00111</a> s16 <a class="code" href="ds1631_8h.html#a25">ds1631GetTH</a>(u08 i2cAddr)00112 {00113     <span class="comment">// read the TH register and return the result</span>00114     <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, DS1631_CMD_ACCESSTH);00115 }00116 <a name="l00117"></a><a class="code" href="ds1631_8h.html#a26">00117</a> s16 <a class="code" href="ds1631_8h.html#a26">ds1631GetTL</a>(u08 i2cAddr)00118 {00119     <span class="comment">// read the TL register and return the result</span>00120     <span class="keywordflow">return</span> ds1631ReadTempReg(i2cAddr, DS1631_CMD_ACCESSTL);00121 }00122 00123 00124 s16 ds1631ReadTempReg(u08 i2cAddr, u08 cmd)00125 {00126     u08 buffer[2];00127     s16 T;00128 00129     <span class="comment">// read the temperature value from the requested register</span>00130     <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, &amp;cmd);00131     <a class="code" href="i2c_8h.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer);00132     <span class="comment">// pack bytes</span>00133     T = (s16)((buffer[0]&lt;&lt;8) | buffer[1]);00134     <span class="comment">// return result</span>00135     <span class="keywordflow">return</span> T;00136 }00137 00138 <span class="keywordtype">void</span> ds1631WriteTempReg(u08 i2cAddr, u08 cmd, s16 value)00139 {00140     u08 buffer[3];00141 00142     <span class="comment">// write the requested register with a temperature value</span>00143     buffer[0] = cmd;00144     buffer[1] = value&gt;&gt;8;00145     buffer[2] = value;00146     <a class="code" href="i2c_8h.html#a24">i2cMasterSendNI</a>(i2cAddr, 3, buffer);00147 }</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 + -