mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Update docs
This commit is contained in:
@@ -2,29 +2,37 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||
<title>ArduinoLibs: DS1307RTC.cpp Source File</title>
|
||||
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
<script type="text/javascript" src="dynsections.js"></script>
|
||||
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="search/search.js"></script>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() { searchBox.OnSelectItem(0); });
|
||||
</script>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body onload='searchBox.OnSelectItem(0);'>
|
||||
<!-- Generated by Doxygen 1.7.4 -->
|
||||
<script type="text/javascript"><!--
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
--></script>
|
||||
<div id="top">
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
<div id="titlearea">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr style="height: 56px;">
|
||||
<td style="padding-left: 0.5em;">
|
||||
<div id="projectname">ArduinoLibs</div>
|
||||
<div id="projectname">ArduinoLibs
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.8.1.2 -->
|
||||
<script type="text/javascript">
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
</script>
|
||||
<div id="navrow1" class="tabs">
|
||||
<ul class="tablist">
|
||||
<li><a href="index.html"><span>Main Page</span></a></li>
|
||||
@@ -32,7 +40,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Classes</span></a></li>
|
||||
<li class="current"><a href="files.html"><span>Files</span></a></li>
|
||||
<li id="searchli">
|
||||
<li>
|
||||
<div id="MSearchBox" class="MSearchBoxInactive">
|
||||
<span class="left">
|
||||
<img id="MSearchSelect" src="search/mag_sel.png"
|
||||
@@ -55,305 +63,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="header">
|
||||
<div class="headertitle">
|
||||
<div class="title">DS1307RTC.cpp</div> </div>
|
||||
</div>
|
||||
<div class="contents">
|
||||
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> *</span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> *</span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included</span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * in all copies or substantial portions of the Software.</span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> *</span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> */</span>
|
||||
<a name="l00022"></a>00022
|
||||
<a name="l00023"></a>00023 <span class="preprocessor">#include "DS1307RTC.h"</span>
|
||||
<a name="l00024"></a>00024 <span class="preprocessor">#include "../I2C/I2CMaster.h"</span>
|
||||
<a name="l00025"></a>00025 <span class="preprocessor">#if defined(ARDUINO) && ARDUINO >= 100</span>
|
||||
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#include <Arduino.h></span>
|
||||
<a name="l00027"></a>00027 <span class="preprocessor">#else</span>
|
||||
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include <WProgram.h></span>
|
||||
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
|
||||
<a name="l00030"></a>00030 <span class="preprocessor"></span>
|
||||
<a name="l00054"></a>00054 <span class="comment">// I2C address of the RTC chip (7-bit).</span>
|
||||
<a name="l00055"></a>00055 <span class="preprocessor">#define DS1307_I2C_ADDRESS 0x68</span>
|
||||
<a name="l00056"></a>00056 <span class="preprocessor"></span>
|
||||
<a name="l00057"></a>00057 <span class="comment">// Registers.</span>
|
||||
<a name="l00058"></a>00058 <span class="preprocessor">#define DS1307_SECOND 0x00</span>
|
||||
<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_MINUTE 0x01</span>
|
||||
<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_HOUR 0x02</span>
|
||||
<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_DAY_OF_WEEK 0x03</span>
|
||||
<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_DATE 0x04</span>
|
||||
<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_MONTH 0x05</span>
|
||||
<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_YEAR 0x06</span>
|
||||
<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_CONTROL 0x07</span>
|
||||
<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_NVRAM 0x08</span>
|
||||
<a name="l00067"></a>00067 <span class="preprocessor"></span>
|
||||
<a name="l00068"></a>00068 <span class="comment">// Alarm storage at the end of the RTC's NVRAM.</span>
|
||||
<a name="l00069"></a>00069 <span class="preprocessor">#define DS1307_ALARM_SIZE 3</span>
|
||||
<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_ALARMS (64 - RTC::ALARM_COUNT * DS1307_ALARM_SIZE - 1)</span>
|
||||
<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#define DS1307_ALARM_MAGIC 63</span>
|
||||
<a name="l00072"></a>00072 <span class="preprocessor"></span>
|
||||
<a name="l00083"></a><a class="code" href="classDS1307RTC.html#a092805d75bea323dc4be062638bff866">00083</a> <a class="code" href="classDS1307RTC.html#a092805d75bea323dc4be062638bff866" title="Attaches to a realtime clock slave device on bus.">DS1307RTC::DS1307RTC</a>(<a class="code" href="classI2CMaster.html" title="Abstract base class for I2C master implementations.">I2CMaster</a> &bus, uint8_t oneHzPin)
|
||||
<a name="l00084"></a>00084 : _bus(&bus)
|
||||
<a name="l00085"></a>00085 , _oneHzPin(oneHzPin)
|
||||
<a name="l00086"></a>00086 , prevOneHz(false)
|
||||
<a name="l00087"></a>00087 , _isRealTime(true)
|
||||
<a name="l00088"></a>00088 {
|
||||
<a name="l00089"></a>00089 <span class="comment">// Make sure the CH bit in register 0 is off or the clock won't update.</span>
|
||||
<a name="l00090"></a>00090 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00091"></a>00091 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_SECOND);
|
||||
<a name="l00092"></a>00092 <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 1)) {
|
||||
<a name="l00093"></a>00093 uint8_t value = _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
|
||||
<a name="l00094"></a>00094 <span class="keywordflow">if</span> ((value & 0x80) != 0)
|
||||
<a name="l00095"></a>00095 writeRegister(DS1307_SECOND, value & 0x7F);
|
||||
<a name="l00096"></a>00096 } <span class="keywordflow">else</span> {
|
||||
<a name="l00097"></a>00097 <span class="comment">// Did not get an acknowledgement from the RTC chip.</span>
|
||||
<a name="l00098"></a>00098 _isRealTime = <span class="keyword">false</span>;
|
||||
<a name="l00099"></a>00099 }
|
||||
<a name="l00100"></a>00100
|
||||
<a name="l00101"></a>00101 <span class="comment">// Turn on the 1 Hz square wave signal if required.</span>
|
||||
<a name="l00102"></a>00102 <span class="keywordflow">if</span> (oneHzPin != 255 && _isRealTime) {
|
||||
<a name="l00103"></a>00103 pinMode(oneHzPin, INPUT);
|
||||
<a name="l00104"></a>00104 digitalWrite(oneHzPin, HIGH);
|
||||
<a name="l00105"></a>00105 writeRegister(DS1307_CONTROL, 0x10);
|
||||
<a name="l00106"></a>00106 }
|
||||
<a name="l00107"></a>00107
|
||||
<a name="l00108"></a>00108 <span class="comment">// Initialize the alarms in the RTC chip's NVRAM.</span>
|
||||
<a name="l00109"></a>00109 <span class="keywordflow">if</span> (_isRealTime)
|
||||
<a name="l00110"></a>00110 initAlarms();
|
||||
<a name="l00111"></a>00111 }
|
||||
<a name="l00112"></a>00112
|
||||
<a name="l00118"></a><a class="code" href="classDS1307RTC.html#a6fec8ff71f33cc1a129eb0bd009600b0">00118</a> <span class="keywordtype">bool</span> <a class="code" href="classDS1307RTC.html#a6fec8ff71f33cc1a129eb0bd009600b0" title="Returns true if the realtime clock has updated since the last call to this function.">DS1307RTC::hasUpdates</a>()
|
||||
<a name="l00119"></a>00119 {
|
||||
<a name="l00120"></a>00120 <span class="comment">// If not using a 1 Hz pin or there is no RTC chip available,</span>
|
||||
<a name="l00121"></a>00121 <span class="comment">// then assume that there is an update available.</span>
|
||||
<a name="l00122"></a>00122 <span class="keywordflow">if</span> (_oneHzPin == 255 || !_isRealTime)
|
||||
<a name="l00123"></a>00123 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
||||
<a name="l00124"></a>00124
|
||||
<a name="l00125"></a>00125 <span class="comment">// The DS1307 updates the internal registers on the falling edge of the</span>
|
||||
<a name="l00126"></a>00126 <span class="comment">// 1 Hz clock. The values should be ready to read on the rising edge.</span>
|
||||
<a name="l00127"></a>00127 <span class="keywordtype">bool</span> value = digitalRead(_oneHzPin);
|
||||
<a name="l00128"></a>00128 <span class="keywordflow">if</span> (value && !prevOneHz) {
|
||||
<a name="l00129"></a>00129 prevOneHz = value;
|
||||
<a name="l00130"></a>00130 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
||||
<a name="l00131"></a>00131 } <span class="keywordflow">else</span> {
|
||||
<a name="l00132"></a>00132 prevOneHz = value;
|
||||
<a name="l00133"></a>00133 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||||
<a name="l00134"></a>00134 }
|
||||
<a name="l00135"></a>00135 }
|
||||
<a name="l00136"></a>00136
|
||||
<a name="l00137"></a>00137 <span class="keyword">inline</span> uint8_t fromBCD(uint8_t value)
|
||||
<a name="l00138"></a>00138 {
|
||||
<a name="l00139"></a>00139 <span class="keywordflow">return</span> (value >> 4) * 10 + (value & 0x0F);
|
||||
<a name="l00140"></a>00140 }
|
||||
<a name="l00141"></a>00141
|
||||
<a name="l00142"></a>00142 <span class="keyword">inline</span> uint8_t fromHourBCD(uint8_t value)
|
||||
<a name="l00143"></a>00143 {
|
||||
<a name="l00144"></a>00144 <span class="keywordflow">if</span> ((value & 0x40) != 0) {
|
||||
<a name="l00145"></a>00145 <span class="comment">// 12-hour mode.</span>
|
||||
<a name="l00146"></a>00146 uint8_t result = ((value >> 4) & 0x01) * 10 + (value & 0x0F);
|
||||
<a name="l00147"></a>00147 <span class="keywordflow">if</span> ((value & 0x20) != 0)
|
||||
<a name="l00148"></a>00148 <span class="keywordflow">return</span> (result == 12) ? 12 : (result + 12); <span class="comment">// PM</span>
|
||||
<a name="l00149"></a>00149 <span class="keywordflow">else</span>
|
||||
<a name="l00150"></a>00150 <span class="keywordflow">return</span> (result == 12) ? 0 : result; <span class="comment">// AM</span>
|
||||
<a name="l00151"></a>00151 } <span class="keywordflow">else</span> {
|
||||
<a name="l00152"></a>00152 <span class="comment">// 24-hour mode.</span>
|
||||
<a name="l00153"></a>00153 <span class="keywordflow">return</span> fromBCD(value);
|
||||
<a name="l00154"></a>00154 }
|
||||
<a name="l00155"></a>00155 }
|
||||
<a name="l00156"></a>00156
|
||||
<a name="l00157"></a><a class="code" href="classDS1307RTC.html#acd9800d6df2244b8e4e790480a1d62a6">00157</a> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#acd9800d6df2244b8e4e790480a1d62a6" title="Reads the current time from the realtime clock into value.">DS1307RTC::readTime</a>(<a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)
|
||||
<a name="l00158"></a>00158 {
|
||||
<a name="l00159"></a>00159 <span class="keywordflow">if</span> (_isRealTime) {
|
||||
<a name="l00160"></a>00160 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00161"></a>00161 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_SECOND);
|
||||
<a name="l00162"></a>00162 <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 3)) {
|
||||
<a name="l00163"></a>00163 value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>() & 0x7F);
|
||||
<a name="l00164"></a>00164 value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
|
||||
<a name="l00165"></a>00165 value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = fromHourBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
|
||||
<a name="l00166"></a>00166 } <span class="keywordflow">else</span> {
|
||||
<a name="l00167"></a>00167 <span class="comment">// RTC chip is not responding.</span>
|
||||
<a name="l00168"></a>00168 value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = 0;
|
||||
<a name="l00169"></a>00169 value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = 0;
|
||||
<a name="l00170"></a>00170 value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = 0;
|
||||
<a name="l00171"></a>00171 }
|
||||
<a name="l00172"></a>00172 } <span class="keywordflow">else</span> {
|
||||
<a name="l00173"></a>00173 <a class="code" href="classDS1307RTC.html#acd9800d6df2244b8e4e790480a1d62a6" title="Reads the current time from the realtime clock into value.">RTC::readTime</a>(value);
|
||||
<a name="l00174"></a>00174 }
|
||||
<a name="l00175"></a>00175 }
|
||||
<a name="l00176"></a>00176
|
||||
<a name="l00177"></a><a class="code" href="classDS1307RTC.html#a6fb56d1690bc30e7995961a5b5e5fdc4">00177</a> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a6fb56d1690bc30e7995961a5b5e5fdc4" title="Reads the current date from the realtime clock into value.">DS1307RTC::readDate</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)
|
||||
<a name="l00178"></a>00178 {
|
||||
<a name="l00179"></a>00179 <span class="keywordflow">if</span> (!_isRealTime) {
|
||||
<a name="l00180"></a>00180 <a class="code" href="classDS1307RTC.html#a6fb56d1690bc30e7995961a5b5e5fdc4" title="Reads the current date from the realtime clock into value.">RTC::readDate</a>(value);
|
||||
<a name="l00181"></a>00181 <span class="keywordflow">return</span>;
|
||||
<a name="l00182"></a>00182 }
|
||||
<a name="l00183"></a>00183 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00184"></a>00184 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_DATE);
|
||||
<a name="l00185"></a>00185 <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 3)) {
|
||||
<a name="l00186"></a>00186 value-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
|
||||
<a name="l00187"></a>00187 value-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
|
||||
<a name="l00188"></a>00188 value-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>()) + 2000;
|
||||
<a name="l00189"></a>00189 } <span class="keywordflow">else</span> {
|
||||
<a name="l00190"></a>00190 <span class="comment">// RTC chip is not responding.</span>
|
||||
<a name="l00191"></a>00191 value-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = 1;
|
||||
<a name="l00192"></a>00192 value-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;
|
||||
<a name="l00193"></a>00193 value-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2000;
|
||||
<a name="l00194"></a>00194 }
|
||||
<a name="l00195"></a>00195 }
|
||||
<a name="l00196"></a>00196
|
||||
<a name="l00197"></a>00197 <span class="keyword">inline</span> uint8_t toBCD(uint8_t value)
|
||||
<a name="l00198"></a>00198 {
|
||||
<a name="l00199"></a>00199 <span class="keywordflow">return</span> ((value / 10) << 4) + (value % 10);
|
||||
<a name="l00200"></a>00200 }
|
||||
<a name="l00201"></a>00201
|
||||
<a name="l00202"></a><a class="code" href="classDS1307RTC.html#a0a5d0d86a0345420ebb289ea724b19e8">00202</a> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a0a5d0d86a0345420ebb289ea724b19e8" title="Updates the time in the realtime clock to match value.">DS1307RTC::writeTime</a>(<span class="keyword">const</span> <a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)
|
||||
<a name="l00203"></a>00203 {
|
||||
<a name="l00204"></a>00204 <span class="keywordflow">if</span> (_isRealTime) {
|
||||
<a name="l00205"></a>00205 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00206"></a>00206 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_SECOND);
|
||||
<a name="l00207"></a>00207 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a>));
|
||||
<a name="l00208"></a>00208 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a>));
|
||||
<a name="l00209"></a>00209 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a>)); <span class="comment">// Changes mode to 24-hour clock.</span>
|
||||
<a name="l00210"></a>00210 _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
|
||||
<a name="l00211"></a>00211 } <span class="keywordflow">else</span> {
|
||||
<a name="l00212"></a>00212 <a class="code" href="classDS1307RTC.html#a0a5d0d86a0345420ebb289ea724b19e8" title="Updates the time in the realtime clock to match value.">RTC::writeTime</a>(value);
|
||||
<a name="l00213"></a>00213 }
|
||||
<a name="l00214"></a>00214 }
|
||||
<a name="l00215"></a>00215
|
||||
<a name="l00216"></a><a class="code" href="classDS1307RTC.html#a4f7346be33612cf9ecd96080eb046230">00216</a> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a4f7346be33612cf9ecd96080eb046230" title="Updates the date in the realtime clock to match value.">DS1307RTC::writeDate</a>(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)
|
||||
<a name="l00217"></a>00217 {
|
||||
<a name="l00218"></a>00218 <span class="keywordflow">if</span> (_isRealTime) {
|
||||
<a name="l00219"></a>00219 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00220"></a>00220 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_DATE);
|
||||
<a name="l00221"></a>00221 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a>));
|
||||
<a name="l00222"></a>00222 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>));
|
||||
<a name="l00223"></a>00223 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> % 100));
|
||||
<a name="l00224"></a>00224 _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
|
||||
<a name="l00225"></a>00225 } <span class="keywordflow">else</span> {
|
||||
<a name="l00226"></a>00226 <a class="code" href="classDS1307RTC.html#a4f7346be33612cf9ecd96080eb046230" title="Updates the date in the realtime clock to match value.">RTC::writeDate</a>(value);
|
||||
<a name="l00227"></a>00227 }
|
||||
<a name="l00228"></a>00228 }
|
||||
<a name="l00229"></a>00229
|
||||
<a name="l00230"></a><a class="code" href="classDS1307RTC.html#aab608eb1630520ee122306b721fdc47a">00230</a> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#aab608eb1630520ee122306b721fdc47a" title="Reads the details of the alarm with index alarmNum into value.">DS1307RTC::readAlarm</a>(uint8_t alarmNum, <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)
|
||||
<a name="l00231"></a>00231 {
|
||||
<a name="l00232"></a>00232 <span class="keywordflow">if</span> (_isRealTime) {
|
||||
<a name="l00233"></a>00233 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00234"></a>00234 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_ALARMS + alarmNum * DS1307_ALARM_SIZE);
|
||||
<a name="l00235"></a>00235 <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 3)) {
|
||||
<a name="l00236"></a>00236 value-><a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
|
||||
<a name="l00237"></a>00237 value-><a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());
|
||||
<a name="l00238"></a>00238 value-><a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
|
||||
<a name="l00239"></a>00239 } <span class="keywordflow">else</span> {
|
||||
<a name="l00240"></a>00240 <span class="comment">// RTC chip is not responding.</span>
|
||||
<a name="l00241"></a>00241 value-><a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 0;
|
||||
<a name="l00242"></a>00242 value-><a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;
|
||||
<a name="l00243"></a>00243 value-><a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;
|
||||
<a name="l00244"></a>00244 }
|
||||
<a name="l00245"></a>00245 } <span class="keywordflow">else</span> {
|
||||
<a name="l00246"></a>00246 <a class="code" href="classDS1307RTC.html#aab608eb1630520ee122306b721fdc47a" title="Reads the details of the alarm with index alarmNum into value.">RTC::readAlarm</a>(alarmNum, value);
|
||||
<a name="l00247"></a>00247 }
|
||||
<a name="l00248"></a>00248 }
|
||||
<a name="l00249"></a>00249
|
||||
<a name="l00250"></a><a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75">00250</a> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75" title="Updates the details of the alarm with index alarmNum from value.">DS1307RTC::writeAlarm</a>(uint8_t alarmNum, <span class="keyword">const</span> <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)
|
||||
<a name="l00251"></a>00251 {
|
||||
<a name="l00252"></a>00252 <span class="keywordflow">if</span> (_isRealTime) {
|
||||
<a name="l00253"></a>00253 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00254"></a>00254 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_ALARMS + alarmNum * DS1307_ALARM_SIZE);
|
||||
<a name="l00255"></a>00255 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a>));
|
||||
<a name="l00256"></a>00256 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a>));
|
||||
<a name="l00257"></a>00257 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value-><a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a>);
|
||||
<a name="l00258"></a>00258 _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
|
||||
<a name="l00259"></a>00259 } <span class="keywordflow">else</span> {
|
||||
<a name="l00260"></a>00260 <a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75" title="Updates the details of the alarm with index alarmNum from value.">RTC::writeAlarm</a>(alarmNum, value);
|
||||
<a name="l00261"></a>00261 }
|
||||
<a name="l00262"></a>00262 }
|
||||
<a name="l00263"></a>00263
|
||||
<a name="l00264"></a><a class="code" href="classDS1307RTC.html#a93c25269a9b78ab3331354db26672248">00264</a> <span class="keywordtype">int</span> <a class="code" href="classDS1307RTC.html#a93c25269a9b78ab3331354db26672248" title="Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings...">DS1307RTC::byteCount</a>()<span class="keyword"> const</span>
|
||||
<a name="l00265"></a>00265 <span class="keyword"></span>{
|
||||
<a name="l00266"></a>00266 <span class="keywordflow">return</span> DS1307_ALARMS - DS1307_NVRAM;
|
||||
<a name="l00267"></a>00267 }
|
||||
<a name="l00268"></a>00268
|
||||
<a name="l00269"></a><a class="code" href="classDS1307RTC.html#a7364609a201022688778ab116c3e4f4a">00269</a> uint8_t <a class="code" href="classDS1307RTC.html#a7364609a201022688778ab116c3e4f4a" title="Reads the byte at offset within the realtime clock's non-volatile memory.">DS1307RTC::readByte</a>(uint8_t offset)
|
||||
<a name="l00270"></a>00270 {
|
||||
<a name="l00271"></a>00271 <span class="keywordflow">if</span> (_isRealTime)
|
||||
<a name="l00272"></a>00272 <span class="keywordflow">return</span> readRegister(DS1307_NVRAM + offset);
|
||||
<a name="l00273"></a>00273 <span class="keywordflow">else</span>
|
||||
<a name="l00274"></a>00274 <span class="keywordflow">return</span> <a class="code" href="classDS1307RTC.html#a7364609a201022688778ab116c3e4f4a" title="Reads the byte at offset within the realtime clock's non-volatile memory.">RTC::readByte</a>(offset);
|
||||
<a name="l00275"></a>00275 }
|
||||
<a name="l00276"></a>00276
|
||||
<a name="l00277"></a><a class="code" href="classDS1307RTC.html#a6ef435fd4aa4adf8eefdf8b1741f5ba6">00277</a> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a6ef435fd4aa4adf8eefdf8b1741f5ba6" title="Writes value to offset within the realtime clock's non-volatile memory.">DS1307RTC::writeByte</a>(uint8_t offset, uint8_t value)
|
||||
<a name="l00278"></a>00278 {
|
||||
<a name="l00279"></a>00279 <span class="keywordflow">if</span> (_isRealTime)
|
||||
<a name="l00280"></a>00280 writeRegister(DS1307_NVRAM + offset, value);
|
||||
<a name="l00281"></a>00281 <span class="keywordflow">else</span>
|
||||
<a name="l00282"></a>00282 <a class="code" href="classDS1307RTC.html#a6ef435fd4aa4adf8eefdf8b1741f5ba6" title="Writes value to offset within the realtime clock's non-volatile memory.">RTC::writeByte</a>(offset, value);
|
||||
<a name="l00283"></a>00283 }
|
||||
<a name="l00284"></a>00284
|
||||
<a name="l00285"></a>00285 <span class="keywordtype">void</span> DS1307RTC::initAlarms()
|
||||
<a name="l00286"></a>00286 {
|
||||
<a name="l00287"></a>00287 uint8_t value = readRegister(DS1307_ALARM_MAGIC);
|
||||
<a name="l00288"></a>00288 <span class="keywordflow">if</span> (value != (0xB0 + <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>)) {
|
||||
<a name="l00289"></a>00289 <span class="comment">// This is the first time we have used this clock chip,</span>
|
||||
<a name="l00290"></a>00290 <span class="comment">// so initialize all alarms to their default state.</span>
|
||||
<a name="l00291"></a>00291 <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> alarm;
|
||||
<a name="l00292"></a>00292 alarm.<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 6; <span class="comment">// Default to 6am for alarms.</span>
|
||||
<a name="l00293"></a>00293 alarm.<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;
|
||||
<a name="l00294"></a>00294 alarm.<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;
|
||||
<a name="l00295"></a>00295 <span class="keywordflow">for</span> (uint8_t index = 0; index < <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>; ++index)
|
||||
<a name="l00296"></a>00296 <a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75" title="Updates the details of the alarm with index alarmNum from value.">writeAlarm</a>(index, &alarm);
|
||||
<a name="l00297"></a>00297 writeRegister(DS1307_ALARM_MAGIC, 0xB0 + ALARM_COUNT);
|
||||
<a name="l00298"></a>00298
|
||||
<a name="l00299"></a>00299 <span class="comment">// Also clear the rest of NVRAM so that it is in a known state.</span>
|
||||
<a name="l00300"></a>00300 <span class="comment">// Otherwise we'll have whatever garbage was present at power-on.</span>
|
||||
<a name="l00301"></a>00301 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00302"></a>00302 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_NVRAM);
|
||||
<a name="l00303"></a>00303 <span class="keywordflow">for</span> (uint8_t index = DS1307_NVRAM; index < DS1307_ALARMS; ++index)
|
||||
<a name="l00304"></a>00304 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(0);
|
||||
<a name="l00305"></a>00305 _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
|
||||
<a name="l00306"></a>00306 }
|
||||
<a name="l00307"></a>00307 }
|
||||
<a name="l00308"></a>00308
|
||||
<a name="l00309"></a>00309 uint8_t DS1307RTC::readRegister(uint8_t reg)
|
||||
<a name="l00310"></a>00310 {
|
||||
<a name="l00311"></a>00311 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00312"></a>00312 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(reg);
|
||||
<a name="l00313"></a>00313 <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 1))
|
||||
<a name="l00314"></a>00314 <span class="keywordflow">return</span> 0; <span class="comment">// RTC chip is not responding.</span>
|
||||
<a name="l00315"></a>00315 <span class="keywordflow">return</span> _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
|
||||
<a name="l00316"></a>00316 }
|
||||
<a name="l00317"></a>00317
|
||||
<a name="l00318"></a>00318 <span class="keywordtype">bool</span> DS1307RTC::writeRegister(uint8_t reg, uint8_t value)
|
||||
<a name="l00319"></a>00319 {
|
||||
<a name="l00320"></a>00320 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);
|
||||
<a name="l00321"></a>00321 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(reg);
|
||||
<a name="l00322"></a>00322 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value);
|
||||
<a name="l00323"></a>00323 <span class="keywordflow">return</span> _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();
|
||||
<a name="l00324"></a>00324 }
|
||||
</pre></div></div>
|
||||
</div>
|
||||
<!-- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
onmouseover="return searchBox.OnSearchSelectShow()"
|
||||
onmouseout="return searchBox.OnSearchSelectHide()"
|
||||
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||||
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a></div>
|
||||
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Pages</a></div>
|
||||
|
||||
<!-- iframe showing the search results (closed by default) -->
|
||||
<div id="MSearchResultsWindow">
|
||||
@@ -362,8 +77,308 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address class="footer"><small>Generated on Mon Jun 18 2012 11:02:51 for ArduinoLibs by 
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||
<div id="nav-path" class="navpath">
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="dir_bc0718b08fb2015b8e59c47b2805f60c.html">libraries</a></li><li class="navelem"><a class="el" href="dir_f34881fcf60f680b800190d5274dfaea.html">RTC</a></li> </ul>
|
||||
</div>
|
||||
</div><!-- top -->
|
||||
<div class="header">
|
||||
<div class="headertitle">
|
||||
<div class="title">DS1307RTC.cpp</div> </div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">/*</span></div>
|
||||
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span></div>
|
||||
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span></div>
|
||||
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span></div>
|
||||
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment"> * to deal in the Software without restriction, including without limitation</span></div>
|
||||
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span></div>
|
||||
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span></div>
|
||||
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span></div>
|
||||
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment"> * The above copyright notice and this permission notice shall be included</span></div>
|
||||
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment"> * in all copies or substantial portions of the Software.</span></div>
|
||||
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</span></div>
|
||||
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span></div>
|
||||
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span></div>
|
||||
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span></div>
|
||||
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span></div>
|
||||
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span></div>
|
||||
<div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment"> * DEALINGS IN THE SOFTWARE.</span></div>
|
||||
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment"> */</span></div>
|
||||
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span> </div>
|
||||
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#include "DS1307RTC.h"</span></div>
|
||||
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#include "../I2C/I2CMaster.h"</span></div>
|
||||
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#if defined(ARDUINO) && ARDUINO >= 100</span></div>
|
||||
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor"></span><span class="preprocessor">#include <Arduino.h></span></div>
|
||||
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#else</span></div>
|
||||
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="preprocessor"></span><span class="preprocessor">#include <WProgram.h></span></div>
|
||||
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor">#endif</span></div>
|
||||
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor"></span></div>
|
||||
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span> <span class="comment">// I2C address of the RTC chip (7-bit).</span></div>
|
||||
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="preprocessor">#define DS1307_I2C_ADDRESS 0x68</span></div>
|
||||
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span> <span class="preprocessor"></span></div>
|
||||
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="comment">// Registers.</span></div>
|
||||
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="preprocessor">#define DS1307_SECOND 0x00</span></div>
|
||||
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_MINUTE 0x01</span></div>
|
||||
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_HOUR 0x02</span></div>
|
||||
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_DAY_OF_WEEK 0x03</span></div>
|
||||
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_DATE 0x04</span></div>
|
||||
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_MONTH 0x05</span></div>
|
||||
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_YEAR 0x06</span></div>
|
||||
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_CONTROL 0x07</span></div>
|
||||
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_NVRAM 0x08</span></div>
|
||||
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span> <span class="preprocessor"></span></div>
|
||||
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span> <span class="comment">// Alarm storage at the end of the RTC's NVRAM.</span></div>
|
||||
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span> <span class="preprocessor">#define DS1307_ALARM_SIZE 3</span></div>
|
||||
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_ALARMS (64 - RTC::ALARM_COUNT * DS1307_ALARM_SIZE - 1)</span></div>
|
||||
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span> <span class="preprocessor"></span><span class="preprocessor">#define DS1307_ALARM_MAGIC 63</span></div>
|
||||
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span> <span class="preprocessor"></span></div>
|
||||
<div class="line"><a name="l00083"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a092805d75bea323dc4be062638bff866"> 83</a></span> <a class="code" href="classDS1307RTC.html#a092805d75bea323dc4be062638bff866" title="Attaches to a realtime clock slave device on bus.">DS1307RTC::DS1307RTC</a>(<a class="code" href="classI2CMaster.html" title="Abstract base class for I2C master implementations.">I2CMaster</a> &bus, uint8_t oneHzPin)</div>
|
||||
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  : _bus(&bus)</div>
|
||||
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  , _oneHzPin(oneHzPin)</div>
|
||||
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  , prevOneHz(false)</div>
|
||||
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  , _isRealTime(true)</div>
|
||||
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span> {</div>
|
||||
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <span class="comment">// Make sure the CH bit in register 0 is off or the clock won't update.</span></div>
|
||||
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_SECOND);</div>
|
||||
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 1)) {</div>
|
||||
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  uint8_t value = _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();</div>
|
||||
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="keywordflow">if</span> ((value & 0x80) != 0)</div>
|
||||
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  writeRegister(DS1307_SECOND, value & 0x7F);</div>
|
||||
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  <span class="comment">// Did not get an acknowledgement from the RTC chip.</span></div>
|
||||
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  _isRealTime = <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  }</div>
|
||||
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span> </div>
|
||||
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <span class="comment">// Turn on the 1 Hz square wave signal if required.</span></div>
|
||||
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="keywordflow">if</span> (oneHzPin != 255 && _isRealTime) {</div>
|
||||
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  pinMode(oneHzPin, INPUT);</div>
|
||||
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  digitalWrite(oneHzPin, HIGH);</div>
|
||||
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  writeRegister(DS1307_CONTROL, 0x10);</div>
|
||||
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  }</div>
|
||||
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span> </div>
|
||||
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  <span class="comment">// Initialize the alarms in the RTC chip's NVRAM.</span></div>
|
||||
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keywordflow">if</span> (_isRealTime)</div>
|
||||
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  initAlarms();</div>
|
||||
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span> }</div>
|
||||
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span> </div>
|
||||
<div class="line"><a name="l00118"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a6fec8ff71f33cc1a129eb0bd009600b0"> 118</a></span> <span class="keywordtype">bool</span> <a class="code" href="classDS1307RTC.html#a6fec8ff71f33cc1a129eb0bd009600b0" title="Returns true if the realtime clock has updated since the last call to this function.">DS1307RTC::hasUpdates</a>()</div>
|
||||
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span> {</div>
|
||||
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <span class="comment">// If not using a 1 Hz pin or there is no RTC chip available,</span></div>
|
||||
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  <span class="comment">// then assume that there is an update available.</span></div>
|
||||
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="keywordflow">if</span> (_oneHzPin == 255 || !_isRealTime)</div>
|
||||
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00124"></a><span class="lineno"> 124</span> </div>
|
||||
<div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  <span class="comment">// The DS1307 updates the internal registers on the falling edge of the</span></div>
|
||||
<div class="line"><a name="l00126"></a><span class="lineno"> 126</span>  <span class="comment">// 1 Hz clock. The values should be ready to read on the rising edge.</span></div>
|
||||
<div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  <span class="keywordtype">bool</span> value = digitalRead(_oneHzPin);</div>
|
||||
<div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <span class="keywordflow">if</span> (value && !prevOneHz) {</div>
|
||||
<div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  prevOneHz = value;</div>
|
||||
<div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  prevOneHz = value;</div>
|
||||
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  }</div>
|
||||
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span> }</div>
|
||||
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span> </div>
|
||||
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span> <span class="keyword">inline</span> uint8_t fromBCD(uint8_t value)</div>
|
||||
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span> {</div>
|
||||
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  <span class="keywordflow">return</span> (value >> 4) * 10 + (value & 0x0F);</div>
|
||||
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span> }</div>
|
||||
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span> </div>
|
||||
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span> <span class="keyword">inline</span> uint8_t fromHourBCD(uint8_t value)</div>
|
||||
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span> {</div>
|
||||
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  <span class="keywordflow">if</span> ((value & 0x40) != 0) {</div>
|
||||
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  <span class="comment">// 12-hour mode.</span></div>
|
||||
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  uint8_t result = ((value >> 4) & 0x01) * 10 + (value & 0x0F);</div>
|
||||
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  <span class="keywordflow">if</span> ((value & 0x20) != 0)</div>
|
||||
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  <span class="keywordflow">return</span> (result == 12) ? 12 : (result + 12); <span class="comment">// PM</span></div>
|
||||
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="keywordflow">else</span></div>
|
||||
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  <span class="keywordflow">return</span> (result == 12) ? 0 : result; <span class="comment">// AM</span></div>
|
||||
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <span class="comment">// 24-hour mode.</span></div>
|
||||
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <span class="keywordflow">return</span> fromBCD(value);</div>
|
||||
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  }</div>
|
||||
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span> }</div>
|
||||
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span> </div>
|
||||
<div class="line"><a name="l00157"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#acd9800d6df2244b8e4e790480a1d62a6"> 157</a></span> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#acd9800d6df2244b8e4e790480a1d62a6" title="Reads the current time from the realtime clock into value.">DS1307RTC::readTime</a>(<a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)</div>
|
||||
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span> {</div>
|
||||
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  <span class="keywordflow">if</span> (_isRealTime) {</div>
|
||||
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_SECOND);</div>
|
||||
<div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 3)) {</div>
|
||||
<div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>() & 0x7F);</div>
|
||||
<div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());</div>
|
||||
<div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = fromHourBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());</div>
|
||||
<div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  <span class="comment">// RTC chip is not responding.</span></div>
|
||||
<div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a> = 0;</div>
|
||||
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a> = 0;</div>
|
||||
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a> = 0;</div>
|
||||
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  }</div>
|
||||
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  <a class="code" href="classDS1307RTC.html#acd9800d6df2244b8e4e790480a1d62a6" title="Reads the current time from the realtime clock into value.">RTC::readTime</a>(value);</div>
|
||||
<div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  }</div>
|
||||
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span> }</div>
|
||||
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span> </div>
|
||||
<div class="line"><a name="l00177"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a6fb56d1690bc30e7995961a5b5e5fdc4"> 177</a></span> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a6fb56d1690bc30e7995961a5b5e5fdc4" title="Reads the current date from the realtime clock into value.">DS1307RTC::readDate</a>(<a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)</div>
|
||||
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span> {</div>
|
||||
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  <span class="keywordflow">if</span> (!_isRealTime) {</div>
|
||||
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  <a class="code" href="classDS1307RTC.html#a6fb56d1690bc30e7995961a5b5e5fdc4" title="Reads the current date from the realtime clock into value.">RTC::readDate</a>(value);</div>
|
||||
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  <span class="keywordflow">return</span>;</div>
|
||||
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  }</div>
|
||||
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_DATE);</div>
|
||||
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 3)) {</div>
|
||||
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  value-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());</div>
|
||||
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  value-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());</div>
|
||||
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  value-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>()) + 2000;</div>
|
||||
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <span class="comment">// RTC chip is not responding.</span></div>
|
||||
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  value-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a> = 1;</div>
|
||||
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  value-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a> = 1;</div>
|
||||
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  value-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> = 2000;</div>
|
||||
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  }</div>
|
||||
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span> }</div>
|
||||
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span> </div>
|
||||
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span> <span class="keyword">inline</span> uint8_t toBCD(uint8_t value)</div>
|
||||
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span> {</div>
|
||||
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  <span class="keywordflow">return</span> ((value / 10) << 4) + (value % 10);</div>
|
||||
<div class="line"><a name="l00200"></a><span class="lineno"> 200</span> }</div>
|
||||
<div class="line"><a name="l00201"></a><span class="lineno"> 201</span> </div>
|
||||
<div class="line"><a name="l00202"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a0a5d0d86a0345420ebb289ea724b19e8"> 202</a></span> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a0a5d0d86a0345420ebb289ea724b19e8" title="Updates the time in the realtime clock to match value.">DS1307RTC::writeTime</a>(<span class="keyword">const</span> <a class="code" href="structRTCTime.html" title="Stores time information from a realtime clock chip.">RTCTime</a> *value)</div>
|
||||
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span> {</div>
|
||||
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  <span class="keywordflow">if</span> (_isRealTime) {</div>
|
||||
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00206"></a><span class="lineno"> 206</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_SECOND);</div>
|
||||
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCTime.html#a87b7c02e535d808dcba04c77e34abb91" title="Second within the minute (0-59)">second</a>));</div>
|
||||
<div class="line"><a name="l00208"></a><span class="lineno"> 208</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCTime.html#acf2161ca037080dc4b767e636ad8db84" title="Minute within the hour (0-59)">minute</a>));</div>
|
||||
<div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCTime.html#a98ba717092ef856dd2b773ba02fcb1a4" title="Hour of the day (0-23)">hour</a>)); <span class="comment">// Changes mode to 24-hour clock.</span></div>
|
||||
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();</div>
|
||||
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  <a class="code" href="classDS1307RTC.html#a0a5d0d86a0345420ebb289ea724b19e8" title="Updates the time in the realtime clock to match value.">RTC::writeTime</a>(value);</div>
|
||||
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  }</div>
|
||||
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span> }</div>
|
||||
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span> </div>
|
||||
<div class="line"><a name="l00216"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a4f7346be33612cf9ecd96080eb046230"> 216</a></span> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a4f7346be33612cf9ecd96080eb046230" title="Updates the date in the realtime clock to match value.">DS1307RTC::writeDate</a>(<span class="keyword">const</span> <a class="code" href="structRTCDate.html" title="Stores date information from a realtime clock chip.">RTCDate</a> *value)</div>
|
||||
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span> {</div>
|
||||
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  <span class="keywordflow">if</span> (_isRealTime) {</div>
|
||||
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_DATE);</div>
|
||||
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCDate.html#a2d68ff3fb90240df522b41222362704c" title="Day of the month (1-31)">day</a>));</div>
|
||||
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCDate.html#a6e6196059b36186041a5312400ea9202" title="Month of the year (1-12)">month</a>));</div>
|
||||
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCDate.html#a7d31822daff3c3fc947386abd897732f" title="Year (4-digit)">year</a> % 100));</div>
|
||||
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();</div>
|
||||
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  <a class="code" href="classDS1307RTC.html#a4f7346be33612cf9ecd96080eb046230" title="Updates the date in the realtime clock to match value.">RTC::writeDate</a>(value);</div>
|
||||
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>  }</div>
|
||||
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span> }</div>
|
||||
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span> </div>
|
||||
<div class="line"><a name="l00230"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#aab608eb1630520ee122306b721fdc47a"> 230</a></span> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#aab608eb1630520ee122306b721fdc47a" title="Reads the details of the alarm with index alarmNum into value.">DS1307RTC::readAlarm</a>(uint8_t alarmNum, <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)</div>
|
||||
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span> {</div>
|
||||
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  <span class="keywordflow">if</span> (_isRealTime) {</div>
|
||||
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00234"></a><span class="lineno"> 234</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_ALARMS + alarmNum * DS1307_ALARM_SIZE);</div>
|
||||
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 3)) {</div>
|
||||
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span>  value-><a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());</div>
|
||||
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  value-><a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = fromBCD(_bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>());</div>
|
||||
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  value-><a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();</div>
|
||||
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span>  <span class="comment">// RTC chip is not responding.</span></div>
|
||||
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  value-><a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 0;</div>
|
||||
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  value-><a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;</div>
|
||||
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span>  value-><a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;</div>
|
||||
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>  }</div>
|
||||
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00246"></a><span class="lineno"> 246</span>  <a class="code" href="classDS1307RTC.html#aab608eb1630520ee122306b721fdc47a" title="Reads the details of the alarm with index alarmNum into value.">RTC::readAlarm</a>(alarmNum, value);</div>
|
||||
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  }</div>
|
||||
<div class="line"><a name="l00248"></a><span class="lineno"> 248</span> }</div>
|
||||
<div class="line"><a name="l00249"></a><span class="lineno"> 249</span> </div>
|
||||
<div class="line"><a name="l00250"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75"> 250</a></span> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75" title="Updates the details of the alarm with index alarmNum from value.">DS1307RTC::writeAlarm</a>(uint8_t alarmNum, <span class="keyword">const</span> <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> *value)</div>
|
||||
<div class="line"><a name="l00251"></a><span class="lineno"> 251</span> {</div>
|
||||
<div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  <span class="keywordflow">if</span> (_isRealTime) {</div>
|
||||
<div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00254"></a><span class="lineno"> 254</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_ALARMS + alarmNum * DS1307_ALARM_SIZE);</div>
|
||||
<div class="line"><a name="l00255"></a><span class="lineno"> 255</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a>));</div>
|
||||
<div class="line"><a name="l00256"></a><span class="lineno"> 256</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(toBCD(value-><a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a>));</div>
|
||||
<div class="line"><a name="l00257"></a><span class="lineno"> 257</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value-><a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a>);</div>
|
||||
<div class="line"><a name="l00258"></a><span class="lineno"> 258</span>  _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();</div>
|
||||
<div class="line"><a name="l00259"></a><span class="lineno"> 259</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00260"></a><span class="lineno"> 260</span>  <a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75" title="Updates the details of the alarm with index alarmNum from value.">RTC::writeAlarm</a>(alarmNum, value);</div>
|
||||
<div class="line"><a name="l00261"></a><span class="lineno"> 261</span>  }</div>
|
||||
<div class="line"><a name="l00262"></a><span class="lineno"> 262</span> }</div>
|
||||
<div class="line"><a name="l00263"></a><span class="lineno"> 263</span> </div>
|
||||
<div class="line"><a name="l00264"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a93c25269a9b78ab3331354db26672248"> 264</a></span> <span class="keywordtype">int</span> <a class="code" href="classDS1307RTC.html#a93c25269a9b78ab3331354db26672248" title="Returns the number of bytes of non-volatile memory that can be used for storage of arbitrary settings...">DS1307RTC::byteCount</a>()<span class="keyword"> const</span></div>
|
||||
<div class="line"><a name="l00265"></a><span class="lineno"> 265</span> <span class="keyword"></span>{</div>
|
||||
<div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  <span class="keywordflow">return</span> DS1307_ALARMS - DS1307_NVRAM;</div>
|
||||
<div class="line"><a name="l00267"></a><span class="lineno"> 267</span> }</div>
|
||||
<div class="line"><a name="l00268"></a><span class="lineno"> 268</span> </div>
|
||||
<div class="line"><a name="l00269"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a7364609a201022688778ab116c3e4f4a"> 269</a></span> uint8_t <a class="code" href="classDS1307RTC.html#a7364609a201022688778ab116c3e4f4a" title="Reads the byte at offset within the realtime clock's non-volatile memory.">DS1307RTC::readByte</a>(uint8_t offset)</div>
|
||||
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span> {</div>
|
||||
<div class="line"><a name="l00271"></a><span class="lineno"> 271</span>  <span class="keywordflow">if</span> (_isRealTime)</div>
|
||||
<div class="line"><a name="l00272"></a><span class="lineno"> 272</span>  <span class="keywordflow">return</span> readRegister(DS1307_NVRAM + offset);</div>
|
||||
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span>  <span class="keywordflow">else</span></div>
|
||||
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  <span class="keywordflow">return</span> <a class="code" href="classDS1307RTC.html#a7364609a201022688778ab116c3e4f4a" title="Reads the byte at offset within the realtime clock's non-volatile memory.">RTC::readByte</a>(offset);</div>
|
||||
<div class="line"><a name="l00275"></a><span class="lineno"> 275</span> }</div>
|
||||
<div class="line"><a name="l00276"></a><span class="lineno"> 276</span> </div>
|
||||
<div class="line"><a name="l00277"></a><span class="lineno"><a class="code" href="classDS1307RTC.html#a6ef435fd4aa4adf8eefdf8b1741f5ba6"> 277</a></span> <span class="keywordtype">void</span> <a class="code" href="classDS1307RTC.html#a6ef435fd4aa4adf8eefdf8b1741f5ba6" title="Writes value to offset within the realtime clock's non-volatile memory.">DS1307RTC::writeByte</a>(uint8_t offset, uint8_t value)</div>
|
||||
<div class="line"><a name="l00278"></a><span class="lineno"> 278</span> {</div>
|
||||
<div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  <span class="keywordflow">if</span> (_isRealTime)</div>
|
||||
<div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  writeRegister(DS1307_NVRAM + offset, value);</div>
|
||||
<div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  <span class="keywordflow">else</span></div>
|
||||
<div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  <a class="code" href="classDS1307RTC.html#a6ef435fd4aa4adf8eefdf8b1741f5ba6" title="Writes value to offset within the realtime clock's non-volatile memory.">RTC::writeByte</a>(offset, value);</div>
|
||||
<div class="line"><a name="l00283"></a><span class="lineno"> 283</span> }</div>
|
||||
<div class="line"><a name="l00284"></a><span class="lineno"> 284</span> </div>
|
||||
<div class="line"><a name="l00285"></a><span class="lineno"> 285</span> <span class="keywordtype">void</span> DS1307RTC::initAlarms()</div>
|
||||
<div class="line"><a name="l00286"></a><span class="lineno"> 286</span> {</div>
|
||||
<div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  uint8_t value = readRegister(DS1307_ALARM_MAGIC);</div>
|
||||
<div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  <span class="keywordflow">if</span> (value != (0xB0 + <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>)) {</div>
|
||||
<div class="line"><a name="l00289"></a><span class="lineno"> 289</span>  <span class="comment">// This is the first time we have used this clock chip,</span></div>
|
||||
<div class="line"><a name="l00290"></a><span class="lineno"> 290</span>  <span class="comment">// so initialize all alarms to their default state.</span></div>
|
||||
<div class="line"><a name="l00291"></a><span class="lineno"> 291</span>  <a class="code" href="structRTCAlarm.html" title="Stores alarm information from a realtime clock chip.">RTCAlarm</a> alarm;</div>
|
||||
<div class="line"><a name="l00292"></a><span class="lineno"> 292</span>  alarm.<a class="code" href="structRTCAlarm.html#a75bdc42acd3ab3ad495680c6b6a34692" title="Hour of the day for the alarm (0-23).">hour</a> = 6; <span class="comment">// Default to 6am for alarms.</span></div>
|
||||
<div class="line"><a name="l00293"></a><span class="lineno"> 293</span>  alarm.<a class="code" href="structRTCAlarm.html#ad9a75ceb4b4b3474baa66dd5466e62fe" title="Minute of the hour for the alarm (0-59).">minute</a> = 0;</div>
|
||||
<div class="line"><a name="l00294"></a><span class="lineno"> 294</span>  alarm.<a class="code" href="structRTCAlarm.html#a0f2ef7363cb60a26642d5295b77ca19e" title="Additional flags for the alarm.">flags</a> = 0;</div>
|
||||
<div class="line"><a name="l00295"></a><span class="lineno"> 295</span>  <span class="keywordflow">for</span> (uint8_t index = 0; index < <a class="code" href="classRTC.html#aee5ae8f600ee5296e65635c0d836fca3" title="Number of alarms that are supported by RTC::readAlarm() and RTC::writeAlarm().">ALARM_COUNT</a>; ++index)</div>
|
||||
<div class="line"><a name="l00296"></a><span class="lineno"> 296</span>  <a class="code" href="classDS1307RTC.html#a7354aed91d7c94d0d7b2144b1bf32c75" title="Updates the details of the alarm with index alarmNum from value.">writeAlarm</a>(index, &alarm);</div>
|
||||
<div class="line"><a name="l00297"></a><span class="lineno"> 297</span>  writeRegister(DS1307_ALARM_MAGIC, 0xB0 + ALARM_COUNT);</div>
|
||||
<div class="line"><a name="l00298"></a><span class="lineno"> 298</span> </div>
|
||||
<div class="line"><a name="l00299"></a><span class="lineno"> 299</span>  <span class="comment">// Also clear the rest of NVRAM so that it is in a known state.</span></div>
|
||||
<div class="line"><a name="l00300"></a><span class="lineno"> 300</span>  <span class="comment">// Otherwise we'll have whatever garbage was present at power-on.</span></div>
|
||||
<div class="line"><a name="l00301"></a><span class="lineno"> 301</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00302"></a><span class="lineno"> 302</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(DS1307_NVRAM);</div>
|
||||
<div class="line"><a name="l00303"></a><span class="lineno"> 303</span>  <span class="keywordflow">for</span> (uint8_t index = DS1307_NVRAM; index < DS1307_ALARMS; ++index)</div>
|
||||
<div class="line"><a name="l00304"></a><span class="lineno"> 304</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(0);</div>
|
||||
<div class="line"><a name="l00305"></a><span class="lineno"> 305</span>  _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();</div>
|
||||
<div class="line"><a name="l00306"></a><span class="lineno"> 306</span>  }</div>
|
||||
<div class="line"><a name="l00307"></a><span class="lineno"> 307</span> }</div>
|
||||
<div class="line"><a name="l00308"></a><span class="lineno"> 308</span> </div>
|
||||
<div class="line"><a name="l00309"></a><span class="lineno"> 309</span> uint8_t DS1307RTC::readRegister(uint8_t reg)</div>
|
||||
<div class="line"><a name="l00310"></a><span class="lineno"> 310</span> {</div>
|
||||
<div class="line"><a name="l00311"></a><span class="lineno"> 311</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00312"></a><span class="lineno"> 312</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(reg);</div>
|
||||
<div class="line"><a name="l00313"></a><span class="lineno"> 313</span>  <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(DS1307_I2C_ADDRESS, 1))</div>
|
||||
<div class="line"><a name="l00314"></a><span class="lineno"> 314</span>  <span class="keywordflow">return</span> 0; <span class="comment">// RTC chip is not responding.</span></div>
|
||||
<div class="line"><a name="l00315"></a><span class="lineno"> 315</span>  <span class="keywordflow">return</span> _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();</div>
|
||||
<div class="line"><a name="l00316"></a><span class="lineno"> 316</span> }</div>
|
||||
<div class="line"><a name="l00317"></a><span class="lineno"> 317</span> </div>
|
||||
<div class="line"><a name="l00318"></a><span class="lineno"> 318</span> <span class="keywordtype">bool</span> DS1307RTC::writeRegister(uint8_t reg, uint8_t value)</div>
|
||||
<div class="line"><a name="l00319"></a><span class="lineno"> 319</span> {</div>
|
||||
<div class="line"><a name="l00320"></a><span class="lineno"> 320</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(DS1307_I2C_ADDRESS);</div>
|
||||
<div class="line"><a name="l00321"></a><span class="lineno"> 321</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(reg);</div>
|
||||
<div class="line"><a name="l00322"></a><span class="lineno"> 322</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value);</div>
|
||||
<div class="line"><a name="l00323"></a><span class="lineno"> 323</span>  <span class="keywordflow">return</span> _bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>();</div>
|
||||
<div class="line"><a name="l00324"></a><span class="lineno"> 324</span> }</div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
Generated on Sun Sep 29 2013 09:30:46 for ArduinoLibs by  <a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
||||
</a> 1.8.1.2
|
||||
</small></address>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user