2      Copyright (C) Dean Camera, 2013. 
   4   dean [at] fourwalledcubicle [dot] com 
  10 bool DS1307_SetTimeDate(const TimeDate_t
* NewTimeDate
) 
  12 #if !defined(DUMMY_RTC) 
  13         DS1307_DateTimeRegs_t NewRegValues
; 
  14         const uint8_t         WriteAddress 
= 0; 
  16         // Convert new time data to the DS1307's time register layout 
  17         NewRegValues
.Byte1
.Fields
.TenSec    
= (NewTimeDate
->Second 
/ 10); 
  18         NewRegValues
.Byte1
.Fields
.Sec       
= (NewTimeDate
->Second 
% 10); 
  19         NewRegValues
.Byte1
.Fields
.CH        
= false; 
  20         NewRegValues
.Byte2
.Fields
.TenMin    
= (NewTimeDate
->Minute 
/ 10); 
  21         NewRegValues
.Byte2
.Fields
.Min       
= (NewTimeDate
->Minute 
% 10); 
  22         NewRegValues
.Byte3
.Fields
.TenHour   
= (NewTimeDate
->Hour 
/ 10); 
  23         NewRegValues
.Byte3
.Fields
.Hour      
= (NewTimeDate
->Hour 
% 10); 
  24         NewRegValues
.Byte3
.Fields
.TwelveHourMode 
= false; 
  26         // Convert new date data to the DS1307's date register layout 
  27         NewRegValues
.Byte4
.Fields
.DayOfWeek 
= 0; 
  28         NewRegValues
.Byte5
.Fields
.TenDay    
= (NewTimeDate
->Day 
/ 10); 
  29         NewRegValues
.Byte5
.Fields
.Day       
= (NewTimeDate
->Day 
% 10); 
  30         NewRegValues
.Byte6
.Fields
.TenMonth  
= (NewTimeDate
->Month 
/ 10); 
  31         NewRegValues
.Byte6
.Fields
.Month     
= (NewTimeDate
->Month 
% 10); 
  32         NewRegValues
.Byte7
.Fields
.TenYear   
= (NewTimeDate
->Year 
/ 10); 
  33         NewRegValues
.Byte7
.Fields
.Year      
= (NewTimeDate
->Year 
% 10); 
  35         // Write the new Time and Date into the DS1307 
  36         if (TWI_WritePacket(DS1307_ADDRESS
, 10, &WriteAddress
, sizeof(WriteAddress
), 
  37                            (uint8_t*)&NewRegValues
, sizeof(DS1307_DateTimeRegs_t
)) != TWI_ERROR_NoError
) 
  46 bool DS1307_GetTimeDate(TimeDate_t
* const TimeDate
) 
  48 #if defined(DUMMY_RTC) 
  57         DS1307_DateTimeRegs_t CurrentRegValues
; 
  58         const uint8_t         ReadAddress 
= 0; 
  60         // Read in the stored Time and Date from the DS1307 
  61         if (TWI_ReadPacket(DS1307_ADDRESS
, 10, &ReadAddress
, sizeof(ReadAddress
), 
  62                            (uint8_t*)&CurrentRegValues
, sizeof(DS1307_DateTimeRegs_t
)) != TWI_ERROR_NoError
) 
  67         // Convert stored time value into decimal 
  68         TimeDate
->Second  
= (CurrentRegValues
.Byte1
.Fields
.TenSec  
* 10) + CurrentRegValues
.Byte1
.Fields
.Sec
; 
  69         TimeDate
->Minute  
= (CurrentRegValues
.Byte2
.Fields
.TenMin  
* 10) + CurrentRegValues
.Byte2
.Fields
.Min
; 
  70         TimeDate
->Hour    
= (CurrentRegValues
.Byte3
.Fields
.TenHour 
* 10) + CurrentRegValues
.Byte3
.Fields
.Hour
; 
  72         // Convert stored date value into decimal 
  73         TimeDate
->Day    
= (CurrentRegValues
.Byte5
.Fields
.TenDay   
* 10) + CurrentRegValues
.Byte5
.Fields
.Day
; 
  74         TimeDate
->Month  
= (CurrentRegValues
.Byte6
.Fields
.TenMonth 
* 10) + CurrentRegValues
.Byte6
.Fields
.Month
; 
  75         TimeDate
->Year   
= (CurrentRegValues
.Byte7
.Fields
.TenYear  
* 10) + CurrentRegValues
.Byte7
.Fields
.Year
;