OwMatch
OwReset ; reset all 1-wire devices
OwWrite(OwMatchRom) ; send "match rom" command
OwWriteBuffer ; send + print rom serial number
btfsc BitMask,2 ; conversion complete?
goto OwScratch ; yes, branch, else
OwWrite(OwConvert) ; send "convert" command
OwPowerBus ; power OW pin during conversion
bcf DataBit
bsf BitMask,2 ; indicate conversion complete
goto OwMatch ; do "match rom" for OwScratch
OwScratch
Send232(' ') ; send <space> char
OwWrite(OwReadScratch) ; send "read scratchpad" command
OwReadByte
movfw OwByte
movwf TempLo
OwReadByte
movfw OwByte
movwf TempHi
ReadLoop
OwReadByte
decfsz BitMask,F
goto ReadLoop
movf RomBuffer,W ; get Family ID byte
xorlw 0x28 ; is it 12 bit DS18B20?
bz OwTemperature ; yes, branch, else
rlf TempLo,F ; |
rlf TempHi,F ;
rlf TempLo,F ;
rlf TempHi,F ;
rlf TempLo,F ;
rlf TempHi,F ;
movlw 0xF0 ;
andwf TempLo,F ;
movlw 16 ;
movwf temp ;
movf OwByte,W ; Count_Remain
subwf temp,W ;
iorwf TempLo,F ; now DS18B20 12 bit format
movlw 4
subwf TempLo,F
skpc
decf TempHi,F
OwTemperature
OwReadByte
OwReadByte
Send232 " "
btfss TempHi,7 ;is it negative
goto NoNegate
Send232 '-' ;Send minus sign
comf TempLo,F ;and negate temperature
comf TempHi,F
incfsz TempLo,F
goto NoNegate
incf TempHi,F
NoNegate
movfw TempLo ;keep fraction part
movwf TempFrac ;and move it to seperate var
movlw 0x0f
andwf TempHi,F ;move nibbles around so
swapf TempLo,F ;that the temperature is
andwf TempLo,F ;contained in TempLo
swapf TempHi,W
iorwf TempLo,F
clrf TempHi ;will contain tens digit
movlw 0x100-.100
addwf TempLo,W
bnc NoHundreds
movwf TempLo
Send232 '1'
bsf BitMask,0 ;no longer suppressing zeros
NoHundreds
movlw .10
subwf TempLo,F
incf TempHi,F
bc NoHundreds
decfsz TempHi,F ;is it zero
goto PrintIt ;no so print it
btfss BitMask,0 ;are we suppressing zeros
goto SkipZero ;yes so skip it
PrintIt movlw '0'
addwf TempHi,W ;print 10s digit
call Put232
SkipZero movlw '0'+10
addwf TempLo,W
call Put232 ;always print units digit
Send232 '.'
call FracDigit
call FracDigit
call FracDigit
call FracDigit
Send232(0x0D) ; send <cr> char
Send232(0x0A) ; send <lf> char
goto OwSearchNext ; search and process next device
FracDigit
movlw 0x0f
andwf TempFrac,F
clrc
rlf TempFrac,W ;*2
movwf temp
rlf temp,W ;*4
addwf TempFrac,F ;*5
rlf TempFrac,F ;*10
swapf TempFrac,W
goto PutNybble