2 Copyright (C) Dean Camera, 2010.
4 dean [at] fourwalledcubicle [dot] com
5 www.fourwalledcubicle.com
10 void DS1307_SetDate(uint8_t Day
, uint8_t Month
, uint8_t Year
)
12 #if defined(DUMMY_RTC)
16 DS1307_DateRegs_t CurrentRTCDate
;
17 CurrentRTCDate
.Byte1
.TenDay
= (Day
/ 10);
18 CurrentRTCDate
.Byte1
.Day
= (Day
% 10);
19 CurrentRTCDate
.Byte2
.TenMonth
= (Month
/ 10);
20 CurrentRTCDate
.Byte2
.Month
= (Month
% 10);
21 CurrentRTCDate
.Byte3
.TenYear
= (Year
/ 10);
22 CurrentRTCDate
.Byte3
.Year
= (Year
% 10);
24 if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
))
26 TWI_SendByte(DS1307_DATEREG_START
);
27 TWI_SendByte(CurrentRTCDate
.Byte1
.IntVal
);
28 TWI_SendByte(CurrentRTCDate
.Byte2
.IntVal
);
29 TWI_SendByte(CurrentRTCDate
.Byte3
.IntVal
);
31 TWI_StopTransmission();
35 void DS1307_SetTime(uint8_t Hour
, uint8_t Minute
, uint8_t Second
)
37 #if defined(DUMMY_RTC)
41 DS1307_TimeRegs_t CurrentRTCTime
;
42 CurrentRTCTime
.Byte1
.TenSec
= (Second
/ 10);
43 CurrentRTCTime
.Byte1
.Sec
= (Second
% 10);
44 CurrentRTCTime
.Byte1
.CH
= false;
45 CurrentRTCTime
.Byte2
.TenMin
= (Minute
/ 10);
46 CurrentRTCTime
.Byte2
.Min
= (Minute
% 10);
47 CurrentRTCTime
.Byte3
.TenHour
= (Hour
/ 10);
48 CurrentRTCTime
.Byte3
.Hour
= (Hour
% 10);
49 CurrentRTCTime
.Byte3
.TwelveHourMode
= false;
51 if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
))
53 TWI_SendByte(DS1307_TIMEREG_START
);
54 TWI_SendByte(CurrentRTCTime
.Byte1
.IntVal
);
55 TWI_SendByte(CurrentRTCTime
.Byte2
.IntVal
);
56 TWI_SendByte(CurrentRTCTime
.Byte3
.IntVal
);
58 TWI_StopTransmission();
62 void DS1307_GetDate(uint8_t* Day
, uint8_t* Month
, uint8_t* Year
)
64 #if defined(DUMMY_RTC)
71 if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
))
73 TWI_SendByte(DS1307_DATEREG_START
);
75 TWI_StopTransmission();
78 DS1307_DateRegs_t CurrentRTCDate
;
80 if (TWI_StartTransmission(DS1307_ADDRESS_READ
))
82 TWI_ReceiveByte(&CurrentRTCDate
.Byte1
.IntVal
, false);
83 TWI_ReceiveByte(&CurrentRTCDate
.Byte2
.IntVal
, false);
84 TWI_ReceiveByte(&CurrentRTCDate
.Byte3
.IntVal
, true);
86 TWI_StopTransmission();
89 *Day
= (CurrentRTCDate
.Byte1
.TenDay
* 10) + CurrentRTCDate
.Byte1
.Day
;
90 *Month
= (CurrentRTCDate
.Byte2
.TenMonth
* 10) + CurrentRTCDate
.Byte2
.Month
;
91 *Year
= (CurrentRTCDate
.Byte3
.TenYear
* 10) + CurrentRTCDate
.Byte3
.Year
;
94 void DS1307_GetTime(uint8_t* Hour
, uint8_t* Minute
, uint8_t* Second
)
96 #if defined(DUMMY_RTC)
103 if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
))
105 TWI_SendByte(DS1307_TIMEREG_START
);
107 TWI_StopTransmission();
110 DS1307_TimeRegs_t CurrentRTCTime
;
112 if (TWI_StartTransmission(DS1307_ADDRESS_READ
))
114 TWI_ReceiveByte(&CurrentRTCTime
.Byte1
.IntVal
, false);
115 TWI_ReceiveByte(&CurrentRTCTime
.Byte2
.IntVal
, false);
116 TWI_ReceiveByte(&CurrentRTCTime
.Byte3
.IntVal
, true);
118 TWI_StopTransmission();
121 *Second
= (CurrentRTCTime
.Byte1
.TenSec
* 10) + CurrentRTCTime
.Byte1
.Sec
;
122 *Minute
= (CurrentRTCTime
.Byte2
.TenMin
* 10) + CurrentRTCTime
.Byte2
.Min
;
123 *Hour
= (CurrentRTCTime
.Byte3
.TenHour
* 10) + CurrentRTCTime
.Byte3
.Hour
;