
// Register addresses of the HT1380 RTC
enum  {RTC_Secs=0, RTC_Mins, RTC_Hours, RTC_Date, RTC_Month, RTC_Day, RTC_Year, RTC_WriteProtect};

// Initialize the rtc if it is not running
void  RTC_Init()
{
byte  tmp;
  
  tmp = RTC_Read(RTC_Secs);             // read seconds register to get the CH bit
  if (0x80 & tmp)                       // if CH bit is set, set defaults and clear it
  {
    RTC_Protect(0);                     // protect off
    RTC_Write(RTC_Secs,tmp & 0x7f);     // clear the CH bit here
    RTC_Write(RTC_Mins,0);
    RTC_Write(RTC_Hours,0x12);          // 24 hour format
    RTC_Write(RTC_Date, 1);             // write date
    RTC_Write(RTC_Month, 1);
    RTC_Write(RTC_Year, 0x06);          // write out the year (2006)
    RTC_Protect(1);                     // protect on
  }
}