Alpha version v0.82 · tstellanova/MCP79412RTC@6b30948 · GitHub
Skip to content

Commit 6b30948

Browse files
author
Jack Christensen
committed
Alpha version v0.82
Added functions to: 1) Read and reset power fail timestamps 2) Enable or disable square wave output 3) Set, enable, disable, test alarms
1 parent 816b313 commit 6b30948

3 files changed

Lines changed: 201 additions & 17 deletions

File tree

MCP79412RTC.cpp

Lines changed: 157 additions & 2 deletions

MCP79412RTC.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@
4646

4747
//MCP7941x Register Addresses
4848
#define TIME_REG 0x00 //7 registers, Seconds, Minutes, Hours, DOW, Date, Month, Year
49+
#define DAY_REG 0x03 //the RTC Day register contains the OSCON, VBAT, and VBATEN bits
50+
#define YEAR_REG 0x06 //RTC year register
4951
#define CTRL_REG 0x07 //control register
5052
#define CALIB_REG 0x08 //calibration register
5153
#define UNLOCK_ID_REG 0x09 //unlock ID register
5254
#define ALM0_REG 0x0A //alarm 0, 6 registers, Seconds, Minutes, Hours, DOW, Date, Month
5355
#define ALM1_REG 0x11 //alarm 1, 6 registers, Seconds, Minutes, Hours, DOW, Date, Month
56+
#define ALM0_DAY 0x0D //DOW register has alarm config/flag bits
5457
#define PWRDWN_TS_REG 0x18 //power-down timestamp, 4 registers, Minutes, Hours, Date, Month
5558
#define PWRUP_TS_REG 0x1C //power-up timestamp, 4 registers, Minutes, Hours, Date, Month
59+
#define TIMESTAMP_SIZE 8 //number of bytes in the two timestamp registers
5660
#define SRAM_START_ADDR 0x20 //first SRAM address
5761
#define SRAM_SIZE 64 //number of bytes of SRAM
5862
#define EEPROM_SIZE 128 //number of bytes of EEPROM
@@ -70,11 +74,7 @@
7074
#define RS2 2 //RS2:0 set square wave output frequency: 0==1Hz, 1==4096Hz, 2==8192Hz, 3=32768Hz
7175
#define RS1 1
7276
#define RS0 0
73-
#define SQWAVE_1_HZ 0
74-
#define SQWAVE_4096_HZ 1
75-
#define SQWAVE_8192_HZ 2
76-
#define SQWAVE_32768_HZ 3
77-
#define SQWAVE_NONE 4
77+
enum {SQWAVE_1_HZ, SQWAVE_4096_HZ, SQWAVE_8192_HZ, SQWAVE_32768_HZ, SQWAVE_NONE};
7878

7979
//Other Control Bits
8080
#define ST 7 //Seconds register (TIME_REG) oscillator start/stop bit, 1==Start, 0==Stop
@@ -92,22 +92,19 @@
9292
#define ALMC1 5
9393
#define ALMC0 4
9494
#define ALMIF 3 //Alarm Interrupt Flag: Set by hardware when an alarm was triggered, cleared by software.
95-
#define ALM_MATCH_SECONDS 0 //Match Seconds
96-
#define ALM_MATCH_MINUTES 1 //Match Minutes
97-
#define ALM_MATCH_HOURS 2 //Match Hours
98-
#define ALM_MATCH_DAY 3 //Match Day (alarm triggers at midnight)
99-
#define ALM_MATCH_DATE 4 //Match Date
100-
#define ALM_MATCH_DATETIME 5 //Match Second, Minute, Hour, Day, Date, Month
101-
95+
enum {ALM_MATCH_SECONDS, ALM_MATCH_MINUTES, ALM_MATCH_HOURS, ALM_MATCH_DAY, ALM_MATCH_DATE, ALM_RESERVED_5, ALM_RESERVED_6, ALM_MATCH_DATETIME, ALM_DISABLE};
96+
//Note ALM_MATCH_DAY triggers alarm at midnight
97+
#define ALARM_0 0 //constants for calling functions
98+
#define ALARM_1 1
10299

103100
class MCP79412RTC
104101
{
105102
public:
106103
MCP79412RTC();
107104
static time_t get(void);
108-
static void set(time_t t);
109-
static void read(tmElements_t &tm);
110-
static void write(tmElements_t &tm);
105+
static void set(time_t t);
106+
static void read(tmElements_t &tm);
107+
static void write(tmElements_t &tm);
111108
void sramWrite(byte addr, byte value);
112109
void sramWrite(byte addr, byte *values, byte nBytes);
113110
byte sramRead(byte addr);
@@ -119,6 +116,11 @@ class MCP79412RTC
119116
int calibRead(void);
120117
void calibWrite(int value);
121118
void idRead(byte *uniqueID);
119+
boolean powerFail(time_t *powerDown, time_t *powerUp);
120+
void squareWave(uint8_t freq);
121+
void setAlarm(uint8_t alarmNumber, time_t alarmTime);
122+
void enableAlarm(uint8_t alarmNumber, uint8_t alarmType);
123+
boolean alarm(uint8_t alarmNumber);
122124

123125
boolean oscStarted(void);
124126

ReadMe.txt

Lines changed: 27 additions & 0 deletions

0 commit comments

Comments
 (0)