Hardware Reference
In-Depth Information
brclr
IBSR,RXAK,sndTimeOK3
; did DS1307 acknowledge?
ldab
#$FF
; return error code 2 1 if not acknowledged
rts
sndTimeOK3
dbne
y,sndloop
; continue until all bytes have been sent out
bclr
IBCR,MSSL
; generate a stop condition.
ldab
#0
; return normal return code 0
rts
The same operation can be performed by the following C function:
char sendTime(char *ptr, char ID)
{
char i;
sendSlaveID(0xD0);
/* send ID to DS1307 */
if(IBSR & RXAK)
/* did DS1307 acknowledge? */
return 2 1;
IBDR 5 0x00;
/* send out seconds register address */
while(!(IBSR & IBIF));
IBSR 5 IBIF;
if(IBSR & RXAK)
return 2 1;
for(i 5 6; i .5 0; i 22 ) {
IBDR 5 *(ptr 1 i);
while(!(IBSR&IBIF));
IBSR 5 IBIF;
if(IBSR & RXAK)
return 2 1;
}
return 0;
}
Example 11.6
Write a C function to read the time of day from the DS1307 and save it in the array
cur_time [0, . . . , 6].
Solution: The following C function will read the time of day from the DS1307:
char readTime(char cx)
{
char i, temp;
sendSlaveID(0xD0);
/* generate a start condition and send DS1307's ID */
if (IBSR & RXAK)
return 2 1;
/* if DS1307 did not respond, return error code *
IBDR 5 cx;
/* send address of seconds register */
while(!(IBSR & IBIF));
IBSR 5 IBIF;
/* clear the IBIF flag */
if (IBSR & RXAK)
return 2 1;
/* if DS1307 did not respond, return error code */
 
Search WWH ::




Custom Search