Dallas DS1620 Interfacing
Listed below is 68HC11 code for talking to a Dallas DS1620.
*-----------------------------------------------------------------------
* file: ds1620.SRC
* description: The subroutine is used to interface to a Dallas 1620.
* author: EMICROS
*
* Assembling Instruction: Use the MOTOROLA Freeware Assembly program.
*-----------------------------------------------------------------------
; define RAM for TEMPmsb and TEMPlsb in application
DQ equ $80 ; data on PORTA
CLK equ $2 ; clock on PORTD
RST equ $20 ; reset on PORTD
ReadTemperature
ldx #$1000 ; set the base register address
bclr <PORTD,x CLK ; make sure the clock line starts low
bset <PACTL,x DQ ; set the DQ line as an output
bset <PORTD,x RST ; set the RST line high to start communication
ldaa #$aa ; load A with READ temperature command
ldab #8 ; set to send 8 bits
zs bclr <PORTA,x DQ ; clear the data line for now
lsra ; rotate bit into carry for compare
bcc ns
bset <PORTA,x DQ ; clear the data line for now
ns bset <PORTD,x CLK ; toggle the clock line, positive edge
bclr <PORTD,x CLK ; clocks in the data
decb ; decrement the loop counter
bne zs ; and repeat if not 0
;
; now let's clock in the temperature, lsb first
;
clr TEMPlsb ; clear the temperature lsb
clr TEMPmsb ; clear the temperature msb
bclr <PACTL,x DQ ; set the DQ line as an input
ldab #8 ; set to receive 8 bits
jj bset <PORTD,x CLK ; set the clock line high to get the data
clc ; clear the carry bit to anticipate a low
brclr <PORTA,x DQ hj ; if data line is low then br
sec ; else set carry hi for shift
hj ror TEMPlsb ; rotate the data into the temperature lsb
bclr <PORTD,x CLK ; set the clock line low
decb ; decrement the loop counter
bne jj ; and repeat if not 0
;
; let's get the last bit
;
bset <PORTD,x CLK ; set the clock line high to get the data
brclr <PORTA,x DQ ad ; if data line is low then br
ldaa #1 ; set the temperature MSB
staa TEMPmsb ;
ad bclr <PORTD,x CLK ; set the clock line low
bset <PORTA,x DQ ; set the DQ line as an output
bclr <PORTD,x RST ; set the RST line lo to end communication
rts
Return to EMICROS software
library page