Hardware Reference
In-Depth Information
IBCR | 5 TXAK;
/* prepare to send NACK */
temp 5 IBDR;
/* a dummy read to trigger nine clock pulses */
while(!(IBSR & IBIF));
IBSR 5 IBIF;
IBCR & 5 , MSSL;
/* generate a stop condition */
return IBDR;
}
Example 11.14
Write a subroutine to read the converted temperature and return the upper and lower bytes
in double accumulator D. Assume that the temperature conversion has been started but this
function needs to make sure that the converted temperature value is a result of the most recent
Start Convert T command.
Solution: This subroutine calls the previous subroutine to make sure that the DONE bit is set
to 1 and reads the converted temperature from the DS1631A. The assembly subroutine is as
follows:
readTemp
ldx
#0
; initialize return error code
rdLoop
jsr
readConf
; is temperature conversion done yet?
cmpb
# 2 1
; is there any error?
beq
rdErr
; “
andb
#$80
; check DONE bit
bpl
rdLoop
; conversion not done yet?
ldaa
#$92
; generate a start condition and send out
jsr
sendSlaveID
; the DS1631A ID
brclr
IBSR,RXAK,rdTempok1
; did DS1631A acknowledge?
ldx
# 2 1
rts
rdTempok1
movb
#$AA,IBDR
; sends Read-Temperature command
brclr
IBSR,IBIF,*
;
movb
#IBIF,IBSR
brclr
IBSR,RXAK,rdTempok2
; did DS1631A acknowledge?
ldx
# 2 1
rts
rdTempok2
bset
IBCR,RSTA
; generate a restart condition
movb
#$93,IBDR
; send DS1631A's ID with R/W set to 1
brclr
IBSR,IBIF,*
movb
#IBIF,IBSR
brclr
IBSR,RXAK,rdTempok3
; did DS1631A acknowledge?
ldx
# 2 1
rts
rdTempok3 bclr
IBCR,TXRX 1 TXAK
; prepare to receive an ACK
ldaa
IBDR
; perform a dummy read
brclr
IBSR,IBIF,*
; wait for high byte of temperature to shift in
movb
#IBIF,IBSR
bset
IBCR,TXAK
; prepare to send NACK for the last read
 
Search WWH ::




Custom Search