Hi If I read the data sheet right the LSB is sent first then the MSB. I haven't written the code but I would think you need to SWAP the nibbles in the LSB then AND the result with 0F hex. Then SWAP the nibbles in the MSB then AND with 07hex. Then OR the LSB with the MSB to get the temperature in binary. Good Luck Dave ----- Original Message ----- From: "KPL" To: "Microcontroller discussion list - Public." Sent: Monday, May 21, 2007 10:27 AM Subject: [PIC] problem with ds18b20 > > > Hello again. > > I'm trying to read temperature with DS18B20, using PIC16F84. > Finally I get some data from that sensor, but it works somehow > strange. When slowly heating a sensor, I see readings like this: > > 22->30->23->31->24->16->25->17->26->18 (celsius) > > Real temperatures are those 22,23,24,25 and so on. but those values in > between are wrong. I can not find where i am doing something wrong:( > > Here is part of the asm, for beginning I am reading only full degrees, > so i take both data bytes, shift them 4 bits to leave integer only, > and then decode and show it on old LED ascii display HDLU-1414. > Program is based on routines from maxim application note 2420. > May be somebody can see the error:) > > > go > clrf led_adr > call hpdl_clear > movlw 0x1b > movwf digits > req_conv > call hpdl_clear > bsf testout > CALL OW_RESET ; reset 1wire > BTFSS PDBYTE,0 ; 1 = PD received > GOTO NOPDPULSE ; if not, error > MOVLW SKPROM > CALL DSTXBYTE ; skip ROM > MOVLW CONVT > CALL DSTXBYTE ; convert temperature > wait_for_ready > > btfss PORTB,DQ > > goto wait_for_ready > CALL OW_RESET ; reset 1wire > BTFSS PDBYTE,0 ; 1 = PD received > GOTO NOPDPULSE ; error > MOVLW SKPROM > CALL DSTXBYTE ; Skip ROM > MOVLW RDSCR > CALL DSTXBYTE ; read scratchpad > CALL DSRXBYTE ; > MOVFW IOBYTE > MOVWF PICMSB ; Put the Current MSB into file PICMSB > CALL DSRXBYTE > MOVFW IOBYTE > MOVWF PICLSB ; Put the Current LSB into file PICLSB > CALL DSRXBYTE > CALL DSRXBYTE > CALL DSRXBYTE > CALL DSRXBYTE > CALL OW_RESET ; reset 1wire > BTFSS PDBYTE,0 ; 1 = PD received > GOTO NOPDPULSE ; if not, error > rrf PICMSB,F > rrf PICMSB,F > rrf PICMSB,F > rrf PICMSB,F ;shift 4 bits R > movlw 15 ;mask for 4 bits > andwf PICMSB,F ;leaving 4 bits > andwf PICLSB,F ;leaving 4 bits > rlf PICLSB,F > rlf PICLSB,F > rlf PICLSB,F > rlf PICLSB,F ;shift 4 bits left > movfw PICLSB > xorwf PICMSB,W ;join both bytes > > movwf BIN > call BIN2BCD > > bcf testout > call hpdl_out > call delay > goto req_conv > > > > -- > KPL > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > > -- > If this email is spam, report it here: > http://www.OnlyMyEmail.com/reportSpam?Id=NTEzMzA6MzE3MDc5MTU1OmRtdW1lcnRAdGVsdXNwbGFuZXQubmV0 > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist