arduino based wordclock
https://www.champonthis.de/projects/wordclock
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.0 KiB
133 lines
3.0 KiB
#ifndef DS3231_h
|
|
#define DS3231_h
|
|
|
|
#include <Arduino.h>
|
|
|
|
/**
|
|
TODO: alarms
|
|
*/
|
|
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 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();
|
|
// helpers
|
|
protected:
|
|
// 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_ALARM1_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
|