diff options
author | William Harrington <kb0iic@berzerkula.org> | 2019-07-31 21:39:03 -0500 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2019-07-31 21:39:03 -0500 |
commit | ea6bafc1320bec14e79b97aad8f072146a11583c (patch) | |
tree | 71e5dfe191edebc3999f20529f5b673395049e1e | |
parent | f98ff594e4488069e5d08b3a1813fd87d2284093 (diff) |
Add a function for determining day of week from calendar date and rename dayofweek to day like in datasheet.
-rwxr-xr-x | ds3231.c | 10 | ||||
-rwxr-xr-x | ds3231.h | 3 |
2 files changed, 9 insertions, 4 deletions
@@ -24,6 +24,10 @@ int DEC_2_BCD(int to_convert) { return ((to_convert / 10) << 4) + (to_convert % 10);
}
+unsigned int Get_DayOfWeek(unsigned int y, unsigned int m, unsigned int d) {
+ return (d += m < 3 ? y-- : y - 2, 23*m/9 + d + 4 + y/4- y/100 + y/400)%7 + 1; // 01 - 07, 01 = Sunday
+}
+
void Read_Alarms_Temp() {
I2C_Master_Start(); // Start I2C
I2C_Master_Write(0xD0); // RTC chip address
@@ -59,11 +63,11 @@ void Set_Date() { I2C_Master_Stop();
}
-void Set_DayOfWeek() {
+void Set_DayOfWeek(int dow) {
I2C_Master_Start(); // Start I2C
I2C_Master_Write(0xD0); // RTC Chip address
I2C_Master_Write(3); // send register address
- I2C_Master_Write(dayOfWeek); //update day of week
+ I2C_Master_Write(dow); //update day of week
I2C_Master_Stop();
}
@@ -89,7 +93,7 @@ void Update_Current_Date_Time() { sec = BCD_2_DEC(I2C_Master_Read(1)); // Read sec from register 00h
min = BCD_2_DEC(I2C_Master_Read(1)); // Read min from register 01h
hour = BCD_2_DEC(I2C_Master_Read(1)); // Read hour from register 02h
- weekday = I2C_Master_Read(1); // Read day from register 03h
+ day = I2C_Master_Read(1); // Read day from register 03h
date = BCD_2_DEC(I2C_Master_Read(1)); // Read date from register 04h
month = BCD_2_DEC(I2C_Master_Read(1)); // Read month from register 05h
year = BCD_2_DEC(I2C_Master_Read(1)); // Read year from register 06h
@@ -2,9 +2,10 @@ int BCD_2_DEC(int);
int DEC_2_BCD(int);
+unsigned int Get_DayOfWeek(unsigned int, unsigned int, unsigned int);
void Read_Alarms_Temp(void);
void Set_Date(void);
-void Set_DayOfWeek(void);
+void Set_DayOfWeek(int);
void Set_Time(void);
void Update_Current_Date_Time(void);
void Write_Alarms(void);
\ No newline at end of file |