Hardware Reference
In-Depth Information
IBCR | 5 RSTA;
/* generate a restart condition */
IBDR 5 0xD1;
/* send ID and set R/W flag to read */
while(!(IBSR & IBIF));
IBSR 5 IBIF;
if (IBSR & RXAK)
return 2 1;
/* if DS1307 did not respond, return error code */
IBCR & 5 , (TXRX 1 TXAK);
/* prepare to receive and acknowledge */
temp 5 IBDR;
/* a dummy read to trigger nine clock pulses */
for (i 5 0; i , 5; i 11 ) {
while(!(IBSR & IBIF));
/* wait for a byte to shift in */
IBSR 5 IBIF;
/* clear the IBIF flag */
cur_time[i] 5 IBDR;
/* save the current time in buffer */
}
/* also initiate the next read */
while (!(IBSR & IBIF));
/* wait for the receipt of cur_time[5] */
IBSR 5 IBIF;
/* clear IBIF flag */
IBCR | 5 TXAK;
/* not to acknowledge cur_time[6] */
cur_time[5] 5 IBDR;
/* save cur_time[5] and initiate next read */
while (!(IBSR & IBIF));
IBSR 5 IBIF;
IBCR & 5 , MSSL;
/* generate stop condition */
cur_time[6] 5 IBDR;
return 0;
}
Example 11.7
Write a function to format the time information stored in the array cur_time [0, . . . , 6] so
that it can be displayed on the LCD.
Solution: The time and calendar information are converted and stored in two character arrays:
hms [0, . . . , 11] and mdy [0, . . . , 11]. The array hms [0, . . . , 11] holds the hours, minutes, and seconds,
whereas the array dmy [0, . . . , 11] holds month, date, and year. The format of display is as follows:
In 24-hour mode,
hh:mm:ss:xx
mm:dd:yy
where xx stands for day of week (can be “SU,” “MO,” “TU,” “WE,” “TH,” “FR,” and “SA”).
In 12-hour mode,
hh:mm:ss:ZM
xx:mm:dd:yy
where Z can be 'A' or 'P' to indicate AM or PM and xx stands for day of week.
The following C function will format the current time of day into two strings:
void formatTime(void)
{
char temp3;
temp3 5 cur_time[3] & 0x07;
/* extract day-of-week */
 
Search WWH ::




Custom Search