-
Notifications
You must be signed in to change notification settings - Fork 1
/
RTCLib.h
73 lines (62 loc) · 1.91 KB
/
RTCLib.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
/*
*******************************************************************
Eng. Abdulkadir MÜHENDİS, M.Sc. Embedded Systems Arcitect
Nextion Basic 3.5 inch with external RTC Module
*******************************************************************
*/
#ifndef RTCLIB
#define RTCLIB
#include "Arduino.h"
#include "Wire.h"
/*
RTC I2C Address:
DS3231 ROM 0x57
DS3231 RTC 0x68
*/
#define RTCLIB_ADDRESS 0x68
#define RTCLIB_EE_ADDRESS 0x57
//Comment to disable RTC-setting function
#define RTCLIB_SET
//Comment to disable EEPROM functionality
#define RTCLIB_EEPROM
// Convert normal decimal numbers to binary coded decimal
#define RTCLIB_decToBcd(val) ((uint8_t) ((val / 10 * 16) + (val % 10)))
//#define RTCLIB_decToBcd(val) ((uint8_t) (val + 6 * (val / 10)))
// Convert binary coded decimal to normal decimal numbers
//#define RTCLIB_bcdToDec(val) ((uint8_t) (val - 6 * (val >> 4)))
#define RTCLIB_bcdToDec(val) ((uint8_t) ((val / 16 * 10) + (val % 16)))
#ifdef _VARIANT_ARDUINO_STM32_
#define RTCLIB_INIT_WIRE() if (_do_init) { _do_init = false; Wire.begin(); }
#endif
class RTCLib {
public:
RTCLib();
uint8_t second();
uint8_t minute();
uint8_t hour();
uint8_t day();
uint8_t month();
uint8_t year();
uint8_t seconds();
uint8_t dayOfWeek();
void refresh();
#ifdef RTCLIB_SET
void set(uint8_t second, uint8_t minute, uint8_t hour, uint8_t dayOfWeek, uint8_t dayOfMonth, uint8_t month, uint8_t year);
#endif
#ifdef RTCLIB_EEPROM
unsigned char eeprom_read(const unsigned int address);
void eeprom_write(const unsigned int address, const unsigned char data);
#endif;
private:
uint8_t _second ;
uint8_t _minute;
uint8_t _hour;
uint8_t _day;
uint8_t _month;
uint8_t _year;
uint8_t _dayOfWeek;
#ifdef _VARIANT_ARDUINO_STM32_
bool _do_init = true;
#endif
};
#endif