Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
MCP79412RTC/examples/SetSerial/SetSerial.ino at boxlambda · epsilon537/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 }}
epsilon537
/
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
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
boxlambda
Breadcrumbs
MCP79412RTC
/
examples
/
SetSerial
/
SetSerial.ino
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
165 lines (147 loc) · 4.83 KB
boxlambda
Breadcrumbs
MCP79412RTC
/
examples
/
SetSerial
/
SetSerial.ino
Copy path
Top
File metadata and controls
Code
Blame
165 lines (147 loc) · 4.83 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//
Arduino MCP79412RTC Library
//
https://github.com/JChristensen/MCP79412RTC
//
Copyright (C) 2018 by Jack Christensen and licensed under
//
GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
//
//
Example sketch. Displays the date and time from an MCP79412 RTC
//
every second.
//
//
Set the date and time by entering the following on the Arduino
//
serial monitor:
//
Syear,month,day,hour,minute,second,
//
//
Where
//
year can be two or four digits,
//
month is 1-12,
//
day is 1-31,
//
hour is 0-23, and
//
minute and second are 0-59.
//
//
Set the calibration register by entering the following:
//
Cnnn,
//
//
Where nnn can be a positive or negative value, e.g. "c4" or "c-42".
//
//
Entering the final comma delimiter (after "second") will avoid a
//
one-second timeout and will allow the RTC to be set more accurately.
//
//
No validity checking is done, invalid values or incomplete syntax
//
in the input will result in an incorrect RTC setting.
//
//
Jack Christensen 28Aug2013
#
include
<
MCP79412RTC.h
>
//
https://github.com/JChristensen/MCP79412RTC
#
include
<
Streaming.h
>
//
http://arduiniana.org/libraries/streaming/
#
include
<
TimeLib.h
>
//
https://github.com/PaulStoffregen/Time
void
setup
()
{
byte rtcID[
8
];
Serial.
begin
(
115200
);
//
setSyncProvider() causes the Time library to synchronize with the
//
external RTC by calling RTC.get() every five minutes by default.
setSyncProvider
(
RTC
.
get
);
Serial << endl <<
F
(
"
RTC Sync
"
);
if
(
timeStatus
() != timeSet) Serial <<
F
(
"
FAIL!
"
);
Serial << endl;
RTC
.
idRead
(rtcID);
Serial <<
F
(
"
RTC ID =
"
);
for
(
int
i=
0
; i<
8
; ++i) {
if
(rtcID[i] <
16
) Serial <<
'
0
'
;
Serial <<
_HEX
(rtcID[i]);
}
Serial << endl;
RTC
.
getEUI64
(rtcID);
Serial <<
F
(
"
EUI-64 =
"
);
for
(
int
i=
0
; i<
8
; ++i) {
if
(rtcID[i] <
16
) Serial <<
'
0
'
;
Serial <<
_HEX
(rtcID[i]);
}
Serial << endl;
Serial <<
F
(
"
Calibration Register =
"
) <<
RTC
.
calibRead
() << endl;
}
void
loop
()
{
static
time_t
tLast;
time_t
t;
tmElements_t tm;
int
cmdChar, y, oldCal, newCal;
//
check for input, first character is a command, "S" to set date/time, or "C" to set the calibration register
if
(Serial.
available
()) {
cmdChar = Serial.
read
();
switch
(cmdChar) {
case
'
S
'
:
case
'
s
'
:
//
note that the tmElements_t Year member is an offset from 1970,
//
but the RTC wants the last two digits of the calendar year.
//
use the convenience macros from TimeLib.h to do the conversions.
y = Serial.
parseInt
();
if
(y >=
100
&& y <
1000
)
Serial <<
F
(
"
Error: Year must be two digits or four digits!
"
) << endl;
else
{
if
(y >=
1000
)
tm.
Year
=
CalendarYrToTm
(y);
else
//
(y < 100)
tm.
Year
=
y2kYearToTm
(y);
tm.
Month
= Serial.
parseInt
();
tm.
Day
= Serial.
parseInt
();
tm.
Hour
= Serial.
parseInt
();
tm.
Minute
= Serial.
parseInt
();
tm.
Second
= Serial.
parseInt
();
t =
makeTime
(tm);
RTC
.
set
(t);
//
use the time_t value to ensure correct weekday is set
setTime
(t);
Serial <<
F
(
"
RTC set to:
"
);
printDateTime
(t);
Serial << endl;
}
break
;
case
'
C
'
:
case
'
c
'
:
newCal = Serial.
parseInt
();
oldCal =
RTC
.
calibRead
();
RTC
.
calibWrite
(newCal);
Serial <<
F
(
"
Calibration changed from
"
) << oldCal <<
F
(
"
to
"
) <<
RTC
.
calibRead
() << endl;
break
;
default
:
Serial << endl <<
F
(
"
Unrecognized command:
"
) << (
char
)cmdChar << endl;
break
;
}
//
dump any extraneous input
while
(Serial.
available
() >
0
) Serial.
read
();
}
t =
now
();
if
(t != tLast) {
tLast = t;
printDateTime
(t);
Serial << endl;
}
}
//
print date and time to Serial
void
printDateTime
(
time_t
t)
{
printDate
(t);
Serial <<
'
'
;
printTime
(t);
}
//
print time to Serial
void
printTime
(
time_t
t)
{
printI00
(
hour
(t),
'
:
'
);
printI00
(
minute
(t),
'
:
'
);
printI00
(
second
(t),
'
'
);
}
//
print date to Serial
void
printDate
(
time_t
t)
{
printI00
(
day
(t),
0
);
Serial <<
monthShortStr
(
month
(t)) <<
_DEC
(
year
(t));
}
//
Print an integer in "00" format (with leading zero),
//
followed by a delimiter character to Serial.
//
Input value assumed to be between 0 and 99.
void
printI00
(
int
val,
char
delim)
{
if
(val <
10
) Serial <<
'
0
'
;
Serial <<
_DEC
(val);
if
(delim >
0
) Serial << delim;
return
;
}
You can’t perform that action at this time.