Application notes 68HC11Endast på Engelska Interfacing the DS1620 to the Motorola SPI BusDallas Semiconductor makes Thermal Management easy with its line of direct-to-digital temperature sensors. These sensors provide a digital reading of temperature directly, eliminating the need for A/D converters dedicated to temperature to digital conversions. Factory-calibrated to relieve the user of linearity corrections and other compensation, Dallas Semiconductor's sensors provide a range and accuracy unparalleled in the industry. * Test program for DS1620 ------ 68HC11** DQ -------- MOSI and MISO tied together* The MOSI can easily be turned off in* the DDRD register.* When a read is performed, the DQ* pin goes to a high impedance state* while the clock is high * (CPOL,CPHA=11 is used).* CLK ------- SCK* RST1 ------ PB0 DS1620 #1* RST2 ------ PB1 DS1620 #2 etc.* You can easily connect several DS1620's** The program reads a DS1620 and converts the temperature* to a readable value in reg Y*************** Equates:*-------------IOBASE equ $1000PORTB equ $1004DDRD equ $1009SPCR equ $1028SPDR equ $102Aportb equ $04 offsetsddrd equ $09spsr equ $29RST1 equ %00000001RST2 equ %00000010 etc.MOSI equ %00001000SPIF equ %10000000St_conv equ %01110111 (mirrored)Rd_temp equ %01010101 (mirrored)Wr_conf equ %00110000 (mirrored)Stack equ $00ff*********************** Initializations:*--------------------- org $f800 RESET lds #Stack jsr InitSPI jsr InitDS************************ Main loop*----------------------Loop jsr Read_DS1 jsr Mirror jsr BtoCent jsr Read_DS2 jsr Mirror jsr BtoCent bra Loop*********************************************** Subroutine Read_DS1* Reads DS1620 #1 and leaves the value* in accB*---------------------------------------------Read_DS1 pshx ldx #IOBASE bset portb,X,RST1 Select DS1620 #1 bsr Read_DS Common routine bclr portb,X,RST1 Deselect #1 pulx rts*********************************************** Subroutine Read_DS2* Reads DS1620 #2 and leaves the value* in accB*---------------------------------------------Read_DS2 pshx ldx #IOBASE bset portb,X,RST2 Select DS1620 #2 bsr Read_DS Common routine bclr portb,X,RST2 Deselect #2 pulx rts*********************************************** Subroutine Read_DS* Reads the DS1620 pointed out by* the RST signal* Leaves the value in accB, sign in accA*---------------------------------------------Read_DS bset ddrd,X,MOSI MOSI on ldab #Rd_temp Read temp command stab SPDR brclr spsr,X,SPIF,* bclr ddrd,X,MOSI MOSI off stab SPDR brclr spsr,X,SPIF,* ldab SPDR stab SPDR brclr spsr,X,SPIF,* ldaa SPDR rts*********************************************** Subroutine InitSPI*---------------------------------------------InitSPI ldaa #%110000 As default, MOSI is turned off staa DDRD ldaa #%01011100 CPOL,CPHA = 11 staa SPCR rts*********************************************** Subroutine InitDS* Initiates both DS1620's for continous* conversion**********************************************InitDS ldx #IOBASE bset portb,X,RST1+RST2 bset ddrd,X,MOSI MOSI on ldaa #Wr_conf Write config staa SPDR brclr spsr,X,SPIF,* ldaa #%01000000 CPU mode, continous conversion staa SPDR brclr spsr,X,SPIF,* bclr portb,X,RST1+RST2 bset portb,X,RST1+RST2 ldaa #St_conv Start convert staa SPDR brclr spsr,X,SPIF,* bclr ddrd,X,MOSI MOSI off bclr portb,X,RST1+RST2 rts******************************************** Subroutine BtoCent* The value in B is converted to Centigrade* in reg Y.*------------------------------------------BtoCent psha pshb pshx clra ldx #20 Divide with 20 idiv pshx pula pula Tenths --> A lslb lslb lslb Units --> B_high bitb #%00001000 Test B_low for %1000 or %0000 beq no if %1000, make it %0101 (5) subb #3no xgdy Put A:B into Y pulx pulb pula rts**************************** Subroutine Mirror* Mirrors the values in B*--------------------------Mirror psha rorb rola rorb rola rorb rola rorb rola rorb rola rorb rola rorb rola rorb rola tab pula rts org $fffe fdb RESET end |
Stefan Nyman © Micronym 1999 |