DS1620, 0.5C resolution mode library for jal ( assembler and jal ) at: http://www.geocities.com/vsurducan/electro/PIC/lib.html regards, Vasile On Wed, 16 Jan 2002, Heinz Czychun wrote: > Hi Michael, > > > > At 8:05 AM -0800 1/15/02, Michael Vinson wrote: > > ...... > > > > >What is going on? Here is a piece of my "read byte" code: > > ....... > > >; The last communication with the DS1616 was sending the low-order byte > >; of the address for the "send page" command. The last thing it did > >; was cycle the sclk (clock) line high and then low. According to > >; the DS1616 data sheet, the next action of the DS1616 is to put the > >; first bit (bit 0) of the data to be read on the i/o pin. > > I think this may be part of the problem..... > > If the DS1616 is like the DS1620 then bit 0 isn't waiting but > must be clocked out. sclk must be high when entering the read > routine, and then brought low. The io bit can then be read into the > PIC. I think your out of sync by one clock. > > >; > > btfsc PORTA,io ; bit 0 should be waiting for us > > bsf dsData,0 ; Bit 0 = 1? If so, set it > > bsf shportA,sclk ; Now cycle the clock high > > updateA > > bcf shportA,sclk ; Bring clock back low > > updateA > > nop ; Just to be sure > > > >; Done with bit 0. Now read bit 1. Someday I'll make this a loop. > > > > btfsc PORTA,io ; Now check if bit 1 is high? > > bsf dsData,1 ; Yes, so set it > > bsf shportA,sclk ; Now cycle the clock high > > updateA > > bcf shportA,sclk ; Bring clock back low > > updateA > > nop ; Just to be sure > > > >[ Code continues to shift the bits in one-by-one by > > repeating the previous 7 lines (with successive.............. > > > Also, if I may be so bold, here are my* read and write routines in > the form of a loop...... > > * Note: This is converted from a 12c509 fan controller done by Peter > Lynch in August 1998 > > ;_____________________________________________ > ; DS1620 Routines > ; > ; Basic write routine to output 8 bits > ; to the DS1620 > ; the byte to send is in the txByte register > ;_____________________________________________ > ; > DS1620wrt > ; > movlw 0x08 ; > movwf bitCount ;setup transmit count for 8 bits > ; > ; write loop > ; > DSwrtLoop > bcf DS1620_CLK ; clock low > bcf DS1620_DQ ; data bit lead low > btfsc txByte, 0 ; check if bit to be transmitted is low > bsf DS1620_DQ ; no, then data bit lead high > ; yes, leave lead low > nop ; short wait > bsf DS1620_CLK ; clock bit into DS1620 on rising edge > > rrf txByte, F ; right shift transmit bit > decfsz bitCount, F ; decrement bit count > goto DSwrtLoop ; do it again, if bit count not zero > ; continue on bit count = zero > return > ;_____________________________________________ > ; > ; Basic read routine, reads 8 bits of data from DS1620 > ; First the read command in txByte has already been sent > ; Leaves data in the rxByte register > ;_____________________________________________ > ; > DS1620rd > ; > ; Use rMask to set the DQ bit to an > ; input to receive the next 8 bits > ; > movlw rMask ; set the DQ pin as input > tris portB > ; > ; receive 8 bits > ; > movlw 0x08 ; setup transmit counter for 8 bits > movwf bitCount > ; > DSrdLoop > rrf rxByte, F ; right shift rxByte register > bcf rxByte, 7 ; clear msb > bcf DS1620_CLK ; lower clock lead > nop ; short wait > btfsc DS1620_DQ ; check DS1620 Data lead > bsf rxByte, 7 ; no, then set msb > bsf DS1620_CLK ; raise clock lead > decfsz bitCount, F ; dec bit count, and check for zero > goto DSrdLoop ; not zero, go around again > ; if zero last bit received > ; > bcf DS1620_RST ; deselect DS1620 > movlw wMask ; reset 0x00 as output > tris portB > return > ;------------------------------------------------------------ > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu