Commits

Wagner Sartori Junior committed 0e711d2

Repository migrated to github

Comments (0)

Files changed (4)

DS3231RTC.cpp

-/*
- * DS3231RTC.h - library for DS#@#! RTC
-  
-  Copyright (c) Wagner Sartori Junior 2011
-  Copyright (c) Michael Margolis 2009
-  This library is intended to be uses with Arduino Time.h library functions
-
-  The library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-  
-  30 Dec 2009 - Initial release
- */
-
-#include <WProgram.h>
-
-#include <Wire.h>
-#include "DS3231RTC.h"
-
-#define DS3231_CTRL_ID 104
-
-DS3231RTC::DS3231RTC()
-{
-  Wire.begin();
-}
-  
-// PUBLIC FUNCTIONS
-time_t DS3231RTC::get()   // Aquire data from buffer and convert to time_t
-{
-  tmElements_t tm;
-  read(tm);
-  return(makeTime(tm));
-}
-
-void  DS3231RTC::set(time_t t)
-{
-  tmElements_t tm;
-  breakTime(t, tm);
-  tm.Second |= 0x80;  // stop the clock
-  write(tm); 
-  tm.Second &= 0x7f;  // start the clock
-  write(tm); 
-}
-
-// Aquire data from the RTC chip in BCD format
-void DS3231RTC::read( tmElements_t &tm)
-{
-  Wire.beginTransmission(DS3231_CTRL_ID);
-  Wire.send(0x00);
-  Wire.endTransmission();
-
-  // request the 7 data fields   (secs, min, hr, dow, date, mth, yr)
-  Wire.requestFrom(DS3231_CTRL_ID, tmNbrFields);
-  
-  tm.Second = bcd2dec(Wire.receive() & 0x7f);   
-  tm.Minute = bcd2dec(Wire.receive() );
-  tm.Hour =   bcd2dec(Wire.receive() & 0x3f);  // mask assumes 24hr clock
-  tm.Wday = bcd2dec(Wire.receive() );
-  tm.Day = bcd2dec(Wire.receive() );
-  tm.Month = bcd2dec(Wire.receive() );
-  tm.Year = y2kYearToTm((bcd2dec(Wire.receive())));
-}
-
-void DS3231RTC::write(tmElements_t &tm)
-{
-  Wire.beginTransmission(DS3231_CTRL_ID);
-  Wire.send(0x00); // reset register pointer
-  
-  Wire.send(dec2bcd(tm.Second)) ;   
-  Wire.send(dec2bcd(tm.Minute));
-  Wire.send(dec2bcd(tm.Hour));      // sets 24 hour format
-  Wire.send(dec2bcd(tm.Wday));   
-  Wire.send(dec2bcd(tm.Day));
-  Wire.send(dec2bcd(tm.Month));
-  Wire.send(dec2bcd(tmYearToY2k(tm.Year)));   
-
-  Wire.endTransmission();  
-}
-
-float DS3231RTC::getTemp()
-{
-  byte tMSB, tLSB;
-  float temp3231;
-
-  //temp registers (11h-12h) get updated automatically every 64s
-  Wire.beginTransmission(DS3231_CTRL_ID);
-  Wire.send(0x11);
-  Wire.endTransmission();
-  Wire.requestFrom(DS3231_CTRL_ID, 2);
-  
-  if(Wire.available()) {
-    tMSB = Wire.receive(); //2's complement int portion
-    tLSB = Wire.receive(); //fraction portion
-    
-    temp3231 = (tMSB & B01111111); //do 2's math on Tmsb
-    temp3231 += ( (tLSB >> 6) * 0.25 ); //only care about bits 7 & 8
-  }
-  else {
-    //oh noes, no data!
-  }
-    
-  return temp3231;
-}
-// PRIVATE FUNCTIONS
-
-// Convert Decimal to Binary Coded Decimal (BCD)
-uint8_t DS3231RTC::dec2bcd(uint8_t num)
-{
-  return ((num/10 * 16) + (num % 10));
-}
-
-// Convert Binary Coded Decimal (BCD) to Decimal
-uint8_t DS3231RTC::bcd2dec(uint8_t num)
-{
-  return ((num/16 * 10) + (num % 16));
-}
-
-DS3231RTC RTC = DS3231RTC(); // create an instance for the user
-

DS3231RTC.h

-/*
- * DS3231RTC.h - library for DS3231 RTC
- * This library is intended to be uses with Arduino Time.h library functions
- */
-
-#ifndef DS3231RTC_h
-#define DS3231RTC_h
-
-#include <Time.h>
-
-// library interface description
-class DS3231RTC
-{
-  // user-accessible "public" interface
-  public:
-    DS3231RTC();
-    static time_t get();
-	static void set(time_t t);
-	static void read(tmElements_t &tm);
-	static void write(tmElements_t &tm);
-	static float getTemp();
-
-  private:
-	static uint8_t dec2bcd(uint8_t num);
-    static uint8_t bcd2dec(uint8_t num);
-};
-
-extern DS3231RTC RTC;
-
-#endif
- 
-

keywords.txt

-#######################################
-# Syntax Coloring Map For DS3231RTC
-#######################################
-
-#######################################
-# Datatypes (KEYWORD1)
-#######################################
-
-#######################################
-# Methods and Functions (KEYWORD2)
-#######################################
-get	KEYWORD2
-set KEYWORD2
-read KEYWORD2
-write KEYWORD2
-#######################################
-# Instances (KEYWORD2)
-#######################################
-RTC
-#######################################
-# Constants (LITERAL1)
-#######################################
-Readme file for DS3231RTC Library
-
-The DS3231RTC library is provided to demonstrate the Arduino Time library.
-
-See the TimeRTC example sketches privided with the Time library download for usage
-
-
+This repository was migrated to: https://github.com/trunet/DS3231RTC