-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathM41T81S.h
More file actions
111 lines (82 loc) · 2.96 KB
/
M41T81S.h
File metadata and controls
111 lines (82 loc) · 2.96 KB
1
/*Copyright (c) 2016, Embedded AdventuresAll rights reserved.Contact us at source [at] embeddedadventures.comwww.embeddedadventures.comRedistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.- Neither the name of Embedded Adventures nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSEARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BELIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/// M41T81S MOD-1005 real-time clock Arduino library// Written originally by Embedded Adventures#ifndef __M41T81S_h#define __M41T81S_h #include "Arduino.h"#define uns8 unsigned int#define RTC_ADDR 0x68/*Register address definitions*/#define rtc_pseconds_reg 0x00#define rtc_seconds_reg 0x01#define rtc_minutes_reg 0x02#define rtc_hours_reg 0x03#define rtc_dow_reg 0x04#define rtc_date_reg 0x05#define rtc_month_reg 0x06 #define rtc_year_reg 0x07class M41T81SClass {private: uns8 bcdToDec(uns8 bcd); uns8 decToBCD(uns8 dec); //uns8 readRegister(uns8 addr); char reg_data[8];public: void writeRegister(uns8 addr, uns8 data); uns8 readRegister(uns8 addr); /*Reset registers 0-7 in RTC*/ void reset(); void init(); /*Returns seconds as int*/ uns8 getSeconds(); /*Returns minutes as int*/ uns8 getMinutes(); /*Returns hours as int*/ uns8 getHours(); /*Returns day of the week as int. 1 = Sunday, 2 = Monday, etc*/ uns8 getDayOfWeek(); /*Returns date of month*/ uns8 getDate(); /*Returns month as int*/ uns8 getMonth(); /*Returns last two digits of current year as int*/ uns8 getYear(); /*Returns 0.01 seconds*/ uns8 getPartSeconds(); void setSeconds(uns8 sec); void setMinutes(uns8 mins); void setHours(uns8 hrs); void setDayOfWeek(uns8 dow); void setDate(uns8 date); void setMonth(uns8 month); void setYear(uns8 year);};extern M41T81SClass rtc;#endif