Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
MCP79412RTC/MCP79412RTC.h at master · jrbenito/MCP79412RTC · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
jrbenito
/
MCP79412RTC
Public
forked from
JChristensen/MCP79412RTC
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
MCP79412RTC
/
MCP79412RTC.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
133 lines (121 loc) · 6.59 KB
master
Breadcrumbs
MCP79412RTC
/
MCP79412RTC.h
Copy path
Top
File metadata and controls
Code
Blame
133 lines (121 loc) · 6.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
----------------------------------------------------------------------*
* MCP79412RTC.h - Arduino library for the Microchip MCP7941x *
* Real-Time Clocks. This library is intended for use with the Arduino *
* Time.h library, http://www.arduino.cc/playground/Code/Time *
* *
* This library is a drop-in replacement for the DS1307RTC.h library *
* by Michael Margolis that is supplied with the Arduino Time library *
* above. To change from using a DS1307 RTC to an MCP7941x RTC, it is *
* only necessary to change the #include statement to include this *
* library instead of DS1307RTC.h. *
* *
* In addition, this library implements functions to support the *
* additional features of the MCP7941x. *
* *
* Jack Christensen 29Jul2012 *
* *
* This work is licensed under the Creative Commons Attribution- *
* ShareAlike 3.0 Unported License. To view a copy of this license, *
* visit http://creativecommons.org/licenses/by-sa/3.0/ or send a *
* letter to Creative Commons, 171 Second Street, Suite 300, *
* San Francisco, California, 94105, USA. *
*----------------------------------------------------------------------
*/
#
ifndef
MCP79412RTC_h
#
define
MCP79412RTC_h
#
include
<
Time.h
>
#
if
defined(ARDUINO) && ARDUINO >= 100
#
include
<
Arduino.h
>
#
else
#
include
<
WProgram.h
>
#
endif
//
MCP7941x I2C Addresses
#
define
RTC_ADDR
0x6F
#
define
EEPROM_ADDR
0x57
//
MCP7941x Register Addresses
#
define
TIME_REG
0x00
//
7 registers, Seconds, Minutes, Hours, DOW, Date, Month, Year
#
define
DAY_REG
0x03
//
the RTC Day register contains the OSCON, VBAT, and VBATEN bits
#
define
YEAR_REG
0x06
//
RTC year register
#
define
CTRL_REG
0x07
//
control register
#
define
CALIB_REG
0x08
//
calibration register
#
define
UNLOCK_ID_REG
0x09
//
unlock ID register
#
define
ALM0_REG
0x0A
//
alarm 0, 6 registers, Seconds, Minutes, Hours, DOW, Date, Month
#
define
ALM1_REG
0x11
//
alarm 1, 6 registers, Seconds, Minutes, Hours, DOW, Date, Month
#
define
ALM0_DAY
0x0D
//
DOW register has alarm config/flag bits
#
define
PWRDWN_TS_REG
0x18
//
power-down timestamp, 4 registers, Minutes, Hours, Date, Month
#
define
PWRUP_TS_REG
0x1C
//
power-up timestamp, 4 registers, Minutes, Hours, Date, Month
#
define
TIMESTAMP_SIZE
8
//
number of bytes in the two timestamp registers
#
define
SRAM_START_ADDR
0x20
//
first SRAM address
#
define
SRAM_SIZE
64
//
number of bytes of SRAM
#
define
EEPROM_SIZE
128
//
number of bytes of EEPROM
#
define
EEPROM_PAGE_SIZE
8
//
number of bytes on an EEPROM page
#
define
UNIQUE_ID_ADDR
0xF0
//
starting address for unique ID
#
define
UNIQUE_ID_SIZE
8
//
number of bytes in unique ID
//
Control Register bits
#
define
OUT
7
//
sets logic level on MFP when not used as square wave output
#
define
SQWE
6
//
set to enable square wave output
#
define
ALM1
5
//
alarm 1 is active
#
define
ALM0
4
//
alarm 0 is active
#
define
EXTOSC
3
//
set to drive the RTC registers from an external oscillator instead of a crystal
#
define
RS2
2
//
RS2:0 set square wave output frequency: 0==1Hz, 1==4096Hz, 2==8192Hz, 3=32768Hz
#
define
RS1
1
#
define
RS0
0
enum
{
SQWAVE_1_HZ
,
SQWAVE_4096_HZ
,
SQWAVE_8192_HZ
,
SQWAVE_32768_HZ
,
SQWAVE_NONE
};
//
Other Control Bits
#
define
ST
7
//
Seconds register (TIME_REG) oscillator start/stop bit, 1==Start, 0==Stop
#
define
HR1224
6
//
Hours register (TIME_REG+2) 12 or 24 hour mode (24 hour mode==0)
#
define
AMPM
5
//
Hours register (TIME_REG+2) AM/PM bit for 12 hour mode
#
define
OSCON
5
//
Day register (TIME_REG+3) oscillator running (set and cleared by hardware)
#
define
VBAT
4
//
Day register (TIME_REG+3) set by hardware when Vcc fails and RTC runs on battery.
//
VBAT is cleared by software, clearing VBAT also clears the timestamp registers
#
define
VBATEN
3
//
Day register (TIME_REG+3) VBATEN==1 enables backup battery, VBATEN==0 disconnects the VBAT pin (e.g. to save battery)
#
define
LP
5
//
Month register (TIME_REG+5) leap year bit
//
Alarm Control Bits
#
define
ALMPOL
7
//
Alarm Polarity: Defines the logic level for the MFP when an alarm is triggered.
#
define
ALMC2
6
//
Alarm configuration bits determine how alarms match. See ALM_MATCH defines below.
#
define
ALMC1
5
#
define
ALMC0
4
#
define
ALMIF
3
//
Alarm Interrupt Flag: Set by hardware when an alarm was triggered, cleared by software.
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
};
//
Note ALM_MATCH_DAY triggers alarm at midnight
#
define
ALARM_0
0
//
constants for calling functions
#
define
ALARM_1
1
class
MCP79412RTC
{
public:
MCP79412RTC
();
static
time_t
get
(
void
);
static
void
set
(
time_t
t);
static
boolean
read
(tmElements_t &tm);
static
void
write
(tmElements_t &tm);
void
sramWrite
(byte addr, byte value);
void
sramWrite
(byte addr, byte *values, byte nBytes);
byte
sramRead
(byte addr);
void
sramRead
(byte addr, byte *values, byte nBytes);
void
eepromWrite
(byte addr, byte value);
void
eepromWrite
(byte addr, byte *values, byte nBytes);
byte
eepromRead
(byte addr);
void
eepromRead
(byte addr, byte *values, byte nBytes);
int
calibRead
(
void
);
void
calibWrite
(
int
value);
void
idRead
(byte *uniqueID);
void
getEUI64
(byte *uniqueID);
boolean
powerFail
(
time_t
*powerDown,
time_t
*powerUp);
void
squareWave
(
uint8_t
freq);
void
setAlarm
(
uint8_t
alarmNumber,
time_t
alarmTime);
void
enableAlarm
(
uint8_t
alarmNumber,
uint8_t
alarmType);
boolean
alarm
(
uint8_t
alarmNumber);
void
out
(boolean level);
void
alarmPolarity
(boolean polarity);
boolean
isRunning
(
void
);
void
vbaten
(boolean enable);
private:
static
void
ramWrite
(byte addr, byte value);
static
void
ramWrite
(byte addr, byte *values, byte nBytes);
static
byte
ramRead
(byte addr);
static
void
ramRead
(byte addr, byte *values, byte nBytes);
static
byte
eepromWait
(
void
);
static
uint8_t
dec2bcd
(
uint8_t
num);
static
uint8_t
bcd2dec
(
uint8_t
num);
};
extern
MCP79412RTC
RTC
;
#
endif
You can’t perform that action at this time.