Hardware Reference
In-Depth Information
After the HCS12 initializes the current time and calendar information, the DS1307 will inter-
rupt the HCS12 periodically (most commonly, once per second) so that the HCS12 can update
the time display periodically.
Example 11.3
Write a function to configure the DS1307 to operate with the following setting:
SQWOUT output enabled
SQWOUT output set to 1 Hz
SQWOUT idle high when it is disabled
Solution: The user needs to send the following bytes to the DS1307:
Address byte $D0 (bit 0 is 0 to select write operation)
Register address $07
Control byte $90 (passed in accumulator B)
The following function will confi gure the DS1307 accordingly:
openDS1307
ldaa
#$D0
; place DS1307 ID in A
jsr
sendSlaveID
brclr
IBSR,RXAK,sndRegAdr
; did DS1307 acknowledge?
ldab
#$FF
; return 2 1 as error code
rts
sndRegAdr
movb
#$07,IBDR
; send out the control register address
brclr
IBSR,IBIF,*
; wait until the register address is shifted out
movb
#IBIF,IBSR
; clear the IBIF flag
brclr
IBSR,RXAK,sndok
; did DS1307 acknowledge?
ldab
#$FF
rts
sndok
stab
IBDR
; send out control byte
brclr
IBSR,IBIF,*
; wait until the control byte is shifted out
movb
#IBIF,IBSR
bclr
IBCR,MSSL
; generate stop condition
rts
The same confi guration can be performed by the following C function:
char openDS1307(char ctrl)
{
sendSlaveID(0xD0);
/* send out DS1307's ID */
if (IBSR & RXAK)
/* if DS1307 did not acknowledge, send error code */
return 2 1;
IBDR 5 0x07;
/* send out control register address */
while(!(IBSR & IBIF));
IBSR 5 IBIF;
/* clear IBIF flag */
if (IBSR & RXAK)
/* if DS1307 did not acknowledge, send error code */
return 2 1;
IBDR 5 ctrl;
/* send out control byte */
while(!(IBSR & IBIF));
IBSR 5 IBIF;
 
Search WWH ::




Custom Search