The DS1307 Serial Real Time Clock is a low–power, full BCD clock/calendar plus 56 bytes of
nonvolatile SRAM. Address and data are transferred serially via the 2–wire bi–directional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with less than 31 days, including corrections for leap year. The clock operates in either the 24–hour or 12–hour format with AM/PM indicator. The DS1307 has a built–in power sense circuit which detects power failures and automatically switches to the battery supply.
SOME FEATURES OF DS1307
- Real time clock counts seconds,minutes,hours, date of month,moth, day of week and year with leap year compensation valid up to 2100
- 56 byte nonvolatile RAM for general data storage
- 2-wrire interface (I2C)
- Automatic power fail detect
- Comsumes less than 500 nA for battery back-up at 25'C
|
 |
|
2-wrie timimg interface
Start data transfer: A change in the state of the data line from high to low, while the clock line is high, defines a START condition.
Stop data transfer: A change in the state of the data line from low to high, while the clock line is high, defines the STOP condition.
Data valid: The state of the data line represents valid data when, after a START condition, the data line is stable for the duration of the high period of the clock signal. The data on the line must be changed during the low period of the clock signal. There is one clock pulse per bit of data. Each data transfer is initiated with a START condition and terminated with a STOP condition. The number of data bytes transferred between the START and the STOP conditions is not limited, and is determined by the master device. The information is transferred byte–wise and each receiver acknowledges with a ninth bit.
Acknowledge: Each receiving device, when addressed, is obliged to generate an acknowledge after the reception of each byte. The master device must generate an extra clock pulse which is associated with this acknowledge bit.
Software
Software for this example program with KEIL C51 V7.5.The main loop just read data from RTC
and keep into array (RCT_ARR[7]) which consist of second,minute,....year.After all data readed it will send to PC for display with hyper terminal program every 1 second.
//---------------------------------------
// Main program
//---------------------------------------
void main(void)
{
InitSerial(); // Initialize serial port
//-----------------------------------
// Setup time and enable oscillator
//-----------------------------------
ReadRTC(&RTC_ARR[0]);
RTC_ARR[0] = RTC_ARR[0] & 0x7F; // enable oscillator (bit 7=0)
RTC_ARR[1] = 0x59; // minute = 59
RTC_ARR[2] = 0x05; // hour = 05 ,24-hour mode(bit 6=0)
RTC_ARR[3] = 0x01; // Day = 1 or sunday
RTC_ARR[4] = 0x30; // Date = 30
RTC_ARR[5] = 0x08; // month = August
RTC_ARR[6] = 0x05; // year = 05 or 2005
WriteRTC(&RTC_ARR[0]); // Set RTC
//-----------------------------------
while(1)
{
ReadRTC(&RTC_ARR[0]);
putchar(0x0C); // clear Hyper terminal
printf("Day : %s\r\n",Int2Day(RTC_ARR[3]));
printf("Time : %02bX:%02bX:%02bX\r\n",RTC_ARR[2],RTC_ARR[1],RTC_ARR[0]);
printf("Data : %02bX-%s-20%02bX",RTC_ARR[4],Int2Month(RTC_ARR[5]),RTC_ARR[6]);
//
DelayMs(1000); // delay about 1 second
}
}
|