2      Copyright (C) Dean Camera, 2010. 
   4   dean [at] fourwalledcubicle [dot] com 
  10 void DS1307_SetDate(const uint8_t Day
, 
  14 #if defined(DUMMY_RTC) 
  18         DS1307_DateRegs_t CurrentRTCDate
; 
  19         CurrentRTCDate
.Byte1
.Fields
.TenDay   
= (Day 
/ 10); 
  20         CurrentRTCDate
.Byte1
.Fields
.Day      
= (Day 
% 10); 
  21         CurrentRTCDate
.Byte2
.Fields
.TenMonth 
= (Month 
/ 10); 
  22         CurrentRTCDate
.Byte2
.Fields
.Month    
= (Month 
% 10); 
  23         CurrentRTCDate
.Byte3
.Fields
.TenYear  
= (Year 
/ 10); 
  24         CurrentRTCDate
.Byte3
.Fields
.Year     
= (Year 
% 10); 
  26         if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
, 10)) 
  28                 TWI_SendByte(DS1307_DATEREG_START
); 
  29                 TWI_SendByte(CurrentRTCDate
.Byte1
.IntVal
); 
  30                 TWI_SendByte(CurrentRTCDate
.Byte2
.IntVal
); 
  31                 TWI_SendByte(CurrentRTCDate
.Byte3
.IntVal
); 
  33                 TWI_StopTransmission(); 
  37 void DS1307_SetTime(const uint8_t Hour
, 
  41 #if defined(DUMMY_RTC) 
  45         DS1307_TimeRegs_t CurrentRTCTime
; 
  46         CurrentRTCTime
.Byte1
.Fields
.TenSec  
= (Second 
/ 10); 
  47         CurrentRTCTime
.Byte1
.Fields
.Sec     
= (Second 
% 10); 
  48         CurrentRTCTime
.Byte1
.Fields
.CH      
= false; 
  49         CurrentRTCTime
.Byte2
.Fields
.TenMin  
= (Minute 
/ 10); 
  50         CurrentRTCTime
.Byte2
.Fields
.Min     
= (Minute 
% 10); 
  51         CurrentRTCTime
.Byte3
.Fields
.TenHour 
= (Hour 
/ 10); 
  52         CurrentRTCTime
.Byte3
.Fields
.Hour    
= (Hour 
% 10); 
  53         CurrentRTCTime
.Byte3
.Fields
.TwelveHourMode 
= false; 
  55         if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
, 10)) 
  57                 TWI_SendByte(DS1307_TIMEREG_START
); 
  58                 TWI_SendByte(CurrentRTCTime
.Byte1
.IntVal
); 
  59                 TWI_SendByte(CurrentRTCTime
.Byte2
.IntVal
); 
  60                 TWI_SendByte(CurrentRTCTime
.Byte3
.IntVal
); 
  62                 TWI_StopTransmission(); 
  66 void DS1307_GetDate(uint8_t* const Day
, 
  70 #if defined(DUMMY_RTC) 
  77         if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
, 10)) 
  79                 TWI_SendByte(DS1307_DATEREG_START
); 
  81                 TWI_StopTransmission(); 
  84         DS1307_DateRegs_t CurrentRTCDate
; 
  86         if (TWI_StartTransmission(DS1307_ADDRESS_READ
, 10)) 
  88                 TWI_ReceiveByte(&CurrentRTCDate
.Byte1
.IntVal
, false); 
  89                 TWI_ReceiveByte(&CurrentRTCDate
.Byte2
.IntVal
, false); 
  90                 TWI_ReceiveByte(&CurrentRTCDate
.Byte3
.IntVal
, true); 
  92                 TWI_StopTransmission(); 
  95         *Day    
= (CurrentRTCDate
.Byte1
.Fields
.TenDay   
* 10) + CurrentRTCDate
.Byte1
.Fields
.Day
; 
  96         *Month  
= (CurrentRTCDate
.Byte2
.Fields
.TenMonth 
* 10) + CurrentRTCDate
.Byte2
.Fields
.Month
; 
  97         *Year   
= (CurrentRTCDate
.Byte3
.Fields
.TenYear  
* 10) + CurrentRTCDate
.Byte3
.Fields
.Year
; 
 100 void DS1307_GetTime(uint8_t* const Hour
, 
 101                     uint8_t* const Minute
, 
 102                     uint8_t* const Second
) 
 104 #if defined(DUMMY_RTC) 
 111         if (TWI_StartTransmission(DS1307_ADDRESS_WRITE
, 10)) 
 113                 TWI_SendByte(DS1307_TIMEREG_START
); 
 115                 TWI_StopTransmission(); 
 118         DS1307_TimeRegs_t CurrentRTCTime
; 
 120         if (TWI_StartTransmission(DS1307_ADDRESS_READ
, 10)) 
 122                 TWI_ReceiveByte(&CurrentRTCTime
.Byte1
.IntVal
, false); 
 123                 TWI_ReceiveByte(&CurrentRTCTime
.Byte2
.IntVal
, false); 
 124                 TWI_ReceiveByte(&CurrentRTCTime
.Byte3
.IntVal
, true); 
 126                 TWI_StopTransmission(); 
 129         *Second  
= (CurrentRTCTime
.Byte1
.Fields
.TenSec  
* 10) + CurrentRTCTime
.Byte1
.Fields
.Sec
; 
 130         *Minute  
= (CurrentRTCTime
.Byte2
.Fields
.TenMin  
* 10) + CurrentRTCTime
.Byte2
.Fields
.Min
; 
 131         *Hour    
= (CurrentRTCTime
.Byte3
.Fields
.TenHour 
* 10) + CurrentRTCTime
.Byte3
.Fields
.Hour
;