-
Notifications
You must be signed in to change notification settings - Fork 0
/
DS1307.h
88 lines (69 loc) · 2.16 KB
/
DS1307.h
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
/********************************************************************************
* DS1307 Library - DS1307.h *
* *
* Copyright (C) 2013 Anil Motilal Mahtani Mirchandani([email protected]) *
* *
* License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> *
* This is free software: you are free to change and redistribute it. *
* There is NO WARRANTY, to the extent permitted by law. *
* *
*********************************************************************************/
#ifndef _DS1307_H
#define _DS1307_H
#include <Arduino.h>
class DS1307
{
public:
struct time
{
int seconds;
int minutes;
int hour;
int day;
int date;
int month;
int year;
};
enum SQW_Freq
{
SQW_1HZ = 0,
SQW_4kHZ = 1,
SQW_8kHZ = 2,
SQW_32kHZ = 3,
};
private:
// Devices address
static const int ADDRESS = 0x68;
// Calibration coefficients addresses
static const int REG_SEC = 0x00;
static const int REG_MIN = 0x01;
static const int REG_HOUR = 0x02;
static const int REG_DAY = 0x03;
static const int REG_DATE = 0x04;
static const int REG_MONTH = 0x05;
static const int REG_YEAR = 0x06;
static const int REG_CTRL = 0x07;
// Calibration coefficients variables
bool output, outputLevel;
SQW_Freq outputFreq;
int readRegister(byte reg_addr, int nbytes, byte *buffer);
int writeRegister(byte reg_addr, int nbytes, byte *buffer);
void setControl();
byte getControl();
byte bcdToDec(byte data);
byte decToBcd(byte data);
public:
DS1307();
void begin();
void end();
void read(time &data);
void write(time &data);
// void set24hour(bool state);
bool getOutput();
void setOutput(bool state);
SQW_Freq getOutputFreq();
void setOutputFreq(SQW_Freq frequency);
bool getOutputLevel();
void setOutputLevel(bool state);
};
#endif // _DS1307_H