ds3231.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef _DS_3231_H_
  2. #define _DS_3231_H_
  3. #define DS3231_ADDR 0x68
  4. typedef union {
  5. struct {
  6. char Value : 7;
  7. char : 1;
  8. };
  9. char AS_BYTE;
  10. } T_SECOND;
  11. typedef union {
  12. struct {
  13. char Value : 7;
  14. char : 1;
  15. };
  16. char AS_BYTE;
  17. } T_MINUTE;
  18. typedef union {
  19. struct {
  20. char Value : 5;
  21. char nAM : 1;
  22. char n24 : 1;
  23. char : 1;
  24. };
  25. char AS_BYTE;
  26. } T_HOUR;
  27. typedef union {
  28. struct {
  29. char Value : 3;
  30. char : 5;
  31. };
  32. char AS_BYTE;
  33. } T_DAY;
  34. typedef union {
  35. struct {
  36. char Value : 6;
  37. char : 2;
  38. };
  39. char AS_BYTE;
  40. } T_DATE;
  41. typedef union {
  42. struct {
  43. char Value : 5;
  44. char : 2;
  45. char Century : 1;
  46. };
  47. char AS_BYTE;
  48. } T_MONTH;
  49. typedef union {
  50. struct {
  51. char Value : 8;
  52. };
  53. char AS_BYTE;
  54. } T_YEAR;
  55. typedef union {
  56. struct {
  57. char Value : 7;
  58. char M1 : 1;
  59. };
  60. char AS_BYTE;
  61. } A_SECOND;
  62. typedef union {
  63. struct {
  64. char Value : 7;
  65. char M2 : 1;
  66. };
  67. char AS_BYTE;
  68. } A_MINUTE;
  69. typedef union {
  70. struct {
  71. char Value : 5;
  72. char nAM : 1;
  73. char n24 : 1;
  74. char M3 : 1;
  75. };
  76. char AS_BYTE;
  77. } A_HOUR;
  78. typedef union {
  79. struct {
  80. char Value : 6;
  81. char nDT : 1;
  82. char M4 : 1;
  83. };
  84. char AS_BYTE;
  85. } A_DAY_DATE;
  86. typedef union {
  87. struct {
  88. char A1IE : 1;
  89. char A2IE : 1;
  90. char INTCN : 1;
  91. char RS1 : 1;
  92. char RS2 : 1;
  93. char CONV : 1;
  94. char BBSQW : 1;
  95. char nEOSC : 1;
  96. };
  97. char AS_BYTE;
  98. } CONTROL_1;
  99. typedef union {
  100. struct {
  101. char A1F : 1;
  102. char A2F : 1;
  103. char BSY : 1;
  104. char EN32KHZ : 1;
  105. char : 3;
  106. char OSF : 1;
  107. };
  108. char AS_BYTE;
  109. } CONTROL_2;
  110. typedef union {
  111. struct {
  112. char Value : 7;
  113. char Sign : 1;
  114. };
  115. char AS_BYTE;
  116. } AGING_OFFSET;
  117. typedef union {
  118. struct {
  119. char Value : 7;
  120. char Sign : 1;
  121. };
  122. char AS_BYTE;
  123. } TEMP_MSB;
  124. typedef union {
  125. struct {
  126. char : 6;
  127. char Value : 2;
  128. };
  129. char AS_BYTE;
  130. } TEMP_LSB;
  131. typedef union {
  132. struct {
  133. T_SECOND Second; // 0x00
  134. T_MINUTE Minute; // 0x01
  135. T_HOUR Hour; // 0x02
  136. T_DAY Day; // 0x03
  137. T_DATE Date; // 0x04
  138. T_MONTH Month; // 0x05
  139. T_YEAR Year; // 0x06
  140. A_SECOND A1_Second; // 0x07
  141. A_MINUTE A1_Minute; // 0x08
  142. A_HOUR A1_Hour; // 0x09
  143. A_DAY_DATE A1_Day_Date; // 0x0A
  144. A_MINUTE A2_Minute; // 0x0B
  145. A_HOUR A2_Hour; // 0x0C
  146. A_DAY_DATE A2_Day_Date; // 0x0D
  147. CONTROL_1 Control_1; // 0x0E
  148. CONTROL_2 Control_2; // 0x0F
  149. AGING_OFFSET Aging_Offset; // 0x10
  150. TEMP_MSB Temp_MSB; // 0x11
  151. TEMP_LSB Temp_LSB; // 0x12
  152. };
  153. char AS_BYTE[0x13];
  154. } DS3231_REGS;
  155. void DS3231_Init(void (*Callback)());
  156. void DS3231_SetTime(int Second, int Minute, int Hour, bool PM);
  157. void DS3231_SetDate(int Day, int Date, int Month, int Year, int Century);
  158. void DS3231_GetTime(int *Second, int *Minute, int *Hour);
  159. #endif