123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #ifndef _DS_3231_H_
- #define _DS_3231_H_
- #define DS3231_ADDR 0x68
- typedef union {
- struct {
- char Value : 7;
- char : 1;
- };
- char AS_BYTE;
- } T_SECOND;
- typedef union {
- struct {
- char Value : 7;
- char : 1;
- };
- char AS_BYTE;
- } T_MINUTE;
- typedef union {
- struct {
- char Value : 6;
- char n24 : 1;
- char : 1;
- };
- char AS_BYTE;
- } T_HOUR;
- typedef union {
- struct {
- char Value : 3;
- char : 5;
- };
- char AS_BYTE;
- } T_DAY;
- typedef union {
- struct {
- char Value : 6;
- char : 2;
- };
- char AS_BYTE;
- } T_DATE;
- typedef union {
- struct {
- char Value : 5;
- char : 2;
- char Century : 1;
- };
- char AS_BYTE;
- } T_MONTH;
- typedef union {
- struct {
- char Value : 8;
- };
- char AS_BYTE;
- } T_YEAR;
- typedef union {
- struct {
- char Value : 7;
- char M1 : 1;
- };
- char AS_BYTE;
- } A_SECOND;
- typedef union {
- struct {
- char Value : 7;
- char M2 : 1;
- };
- char AS_BYTE;
- } A_MINUTE;
- typedef union {
- struct {
- char Value : 6;
- char n24 : 1;
- char M3 : 1;
- };
- char AS_BYTE;
- } A_HOUR;
- typedef union {
- struct {
- char Value : 6;
- char nDT : 1;
- char M4 : 1;
- };
- char AS_BYTE;
- } A_DAY_DATE;
- typedef union {
- struct {
- char A1IE : 1;
- char A2IE : 1;
- char INTCN : 1;
- char RS1 : 1;
- char RS2 : 1;
- char CONV : 1;
- char BBSQW : 1;
- char nEOSC : 1;
- };
- char AS_BYTE;
- } CONTROL_1;
- typedef union {
- struct {
- char A1F : 1;
- char A2F : 1;
- char BSY : 1;
- char EN32KHZ : 1;
- char : 3;
- char OSF : 1;
- };
- char AS_BYTE;
- } CONTROL_2;
- typedef union {
- struct {
- char Value : 7;
- char Sign : 1;
- };
- char AS_BYTE;
- } AGING_OFFSET;
- typedef union {
- struct {
- char Value : 7;
- char Sign : 1;
- };
- char AS_BYTE;
- } TEMP_MSB;
- typedef union {
- struct {
- char : 6;
- char Value : 2;
- };
- char AS_BYTE;
- } TEMP_LSB;
- typedef union {
- struct {
- T_SECOND Second; // 0x00
- T_MINUTE Minute; // 0x01
- T_HOUR Hour; // 0x02
- T_DAY DayOfWeek; // 0x03
- T_DATE Day; // 0x04
- T_MONTH Month; // 0x05
- T_YEAR Year; // 0x06
- A_SECOND A1_Second; // 0x07
- A_MINUTE A1_Minute; // 0x08
- A_HOUR A1_Hour; // 0x09
- A_DAY_DATE A1_Day_Date; // 0x0A
- A_MINUTE A2_Minute; // 0x0B
- A_HOUR A2_Hour; // 0x0C
- A_DAY_DATE A2_Day_Date; // 0x0D
- CONTROL_1 Control_1; // 0x0E
- CONTROL_2 Control_2; // 0x0F
- AGING_OFFSET Aging_Offset; // 0x10
- TEMP_MSB Temp_MSB; // 0x11
- TEMP_LSB Temp_LSB; // 0x12
- };
- char AS_BYTE[0x13];
- } DS3231_REGS;
- enum {
- SUNDAY = 1,
- MONDAY = 2,
- TUESDAY = 3,
- WEDNESDAY = 4,
- THURSDAY = 5,
- FRIDAY = 6,
- SATURDAY = 7
- };
- void DS3231_Init(void (*Callback)());
- void DS3231_SetTime(int Second, int Minute, int Hour);
- void DS3231_SetDate(int DayOfWeek, int Day, int Month, int Year, int Century);
- void DS3231_GetTime(int *Second, int *Minute, int *Hour);
- void DS3231_GetDate(int *DayOfWeek, int *Day, int *Month, int *Year);
- bool IsDst(int DayOfWeek, int Day, int Month, int Hour_24);
- #endif
|