163 lines
3.9 KiB
C++
163 lines
3.9 KiB
C++
#ifndef DS3231_h
|
|
#define DS3231_h
|
|
|
|
#include <Arduino.h>
|
|
|
|
/**
|
|
*
|
|
*/
|
|
class DS3231
|
|
{
|
|
public:
|
|
// begin function
|
|
void begin();
|
|
// get seconds
|
|
uint8_t getSeconds();
|
|
// set seconds
|
|
void setSeconds(uint8_t seconds);
|
|
// increment seconds
|
|
void incrementSeconds();
|
|
// decrement seconds
|
|
void decrementSeconds();
|
|
// get minutes
|
|
uint8_t getMinutes();
|
|
// set minutes
|
|
void setMinutes(uint8_t minutes);
|
|
// increment minutes
|
|
void incrementMinutes();
|
|
// decrement minutes
|
|
void decrementMinutes();
|
|
// get hours
|
|
uint8_t getHours();
|
|
// set hours
|
|
void setHours(uint8_t hours);
|
|
// increment hours
|
|
void incrementHours();
|
|
// decrement hours
|
|
void decrementHours();
|
|
// get day
|
|
uint8_t getDay();
|
|
// set day
|
|
void setDay(uint8_t day);
|
|
// get date
|
|
uint8_t getDate();
|
|
// set date
|
|
void setDate(uint8_t date);
|
|
// increment date
|
|
void incrementDate();
|
|
// decrement date
|
|
void decrementDate();
|
|
// get month
|
|
uint8_t getMonth();
|
|
// set month
|
|
void setMonth(uint8_t month);
|
|
// increment month
|
|
void incrementMonth();
|
|
// decrement month
|
|
void decrementMonth();
|
|
// get year
|
|
int16_t getYear();
|
|
// set year
|
|
void setYear(int16_t year);
|
|
// increment year
|
|
void incrementYear();
|
|
// decrement year
|
|
void decrementYear();
|
|
// get alarm1 seconds
|
|
uint8_t getAlarm1Seconds();
|
|
// set alarm1 seconds
|
|
void setAlarm1Seconds(uint8_t seonds);
|
|
// get alarm1 minutes
|
|
uint8_t getAlarm1Minutes();
|
|
// set alarm1 Minutes
|
|
void setAlarm1Minutes(uint8_t minutes);
|
|
// get alarm1 hours
|
|
uint8_t getAlarm1Hours();
|
|
// set alarm1 hours
|
|
void setAlarm1Hours(uint8_t hours);
|
|
// get alarm1 date
|
|
uint8_t getAlarm1Date();
|
|
// set alarm1 data
|
|
void setAlarm1Date(uint8_t date);
|
|
// set alarm1 mask
|
|
void setAlarm1Mask(uint8_t mask);
|
|
// get alarm2 minutes
|
|
uint8_t getAlarm2Minutes();
|
|
// set alarm2 Minutes
|
|
void setAlarm2Minutes(uint8_t minutes);
|
|
// get alarm2 hours
|
|
uint8_t getAlarm2Hours();
|
|
// set alarm2 hours
|
|
void setAlarm2Hours(uint8_t hours);
|
|
// get alarm2 date
|
|
uint8_t getAlarm2Date();
|
|
// set alarm2 data
|
|
void setAlarm2Date(uint8_t date);
|
|
// set alarm2 mask
|
|
void setAlarm2Mask(uint8_t mask);
|
|
// get control register
|
|
uint8_t getControlRegister();
|
|
// set control register
|
|
void setControlRegister(uint8_t value);
|
|
// set status register
|
|
uint8_t getStatusRegister();
|
|
// set status register
|
|
void setStatusRegister(uint8_t value);
|
|
// get temperature
|
|
uint8_t getTemperature();
|
|
// get register
|
|
uint8_t getRegister(uint8_t address);
|
|
// set register
|
|
void setRegister(uint8_t address, uint8_t value);
|
|
// decimal to binary coded decimal
|
|
uint8_t dectobcd(uint8_t value);
|
|
// binary coded decimal to decimal
|
|
uint8_t bcdtodec(uint8_t value);
|
|
// get century value
|
|
uint8_t getCentury();
|
|
// set century value
|
|
void setCentury(uint8_t century);
|
|
};
|
|
|
|
// I2C address
|
|
#define DS3231_I2C_ADDRESS 0x68
|
|
|
|
// I2C registers
|
|
#define DS3231_SECONDS 0x00
|
|
#define DS3231_MINUTES 0x01
|
|
#define DS3231_HOURS 0x02
|
|
#define DS3231_DAY 0x03
|
|
#define DS3231_DATE 0x04
|
|
#define DS3231_MONTH 0x05
|
|
#define DS3231_YEAR 0x06
|
|
#define DS3231_ALARM1_SECONDS 0x07
|
|
#define DS3231_ALARM1_MINUTES 0x08
|
|
#define DS3231_ALARM1_HOURS 0x09
|
|
#define DS3231_ALARM1_DATE 0x0A
|
|
#define DS3231_ALARM2_MINUTES 0x0B
|
|
#define DS3231_ALARM2_HOURS 0x0C
|
|
#define DS3231_ALARM2_DATE 0x0D
|
|
#define DS3231_CONTROL 0x0E
|
|
#define DS3231_STATUS 0x0F
|
|
#define DS3231_AGING_OFFSET 0x10
|
|
#define DS3231_MSB_TEMP 0x11
|
|
#define DS3231_LSB_TEMP 0x12
|
|
|
|
// control registers
|
|
#define DS3231_CONTROL_A1IE 0x01
|
|
#define DS3231_CONTROL_A2IE 0x02
|
|
#define DS3231_CONTROL_INTCN 0x04
|
|
#define DS3231_CONTROL_RS1 0x08
|
|
#define DS3231_CONTROL_RS2 0x10
|
|
#define DS3231_CONTROL_CONV 0x20
|
|
#define DS3231_CONTROL_BBSQW 0x40
|
|
#define DS3231_CONTROL_EOSC 0x80
|
|
|
|
// status registers
|
|
#define DS3231_STATUSL_A1F 0x01
|
|
#define DS3231_STATUSL_A2F 0x02
|
|
#define DS3231_STATUSL_BSY 0x04
|
|
#define DS3231_STATUSL_EN32KHZ 0x08
|
|
#define DS3231_STATUSL_OSF 0x80
|
|
|
|
#endif |