-
Notifications
You must be signed in to change notification settings - Fork 42
/
8.2.1.2-1307Read.ino
58 lines (55 loc) · 1.28 KB
/
8.2.1.2-1307Read.ino
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
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
void setup()
{
Serial.begin(9600);
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
}
void loop()
{
tmElements_t tm;
// 读出DS1307中的时间数据
if (RTC.read(tm))
{
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
}
else
{
if (RTC.chipPresent())
{
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
}
else
{
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}
void print2digits(int number)
{
if (number >= 0 && number < 10)
{
Serial.write('0');
}
Serial.print(number);
}