aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xds3231.c10
-rwxr-xr-xds3231.h3
2 files changed, 9 insertions, 4 deletions
diff --git a/ds3231.c b/ds3231.c
index c7cd797..b70a09b 100755
--- a/ds3231.c
+++ b/ds3231.c
@@ -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
diff --git a/ds3231.h b/ds3231.h
index c6a326a..3131310 100755
--- a/ds3231.h
+++ b/ds3231.h
@@ -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