Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

HELP DS18b20 negative reading

Status
Not open for further replies.

mastero

Member
'PIC18F2520
Define CLOCK_FREQUENCY = 12
AllDigital
'Define SIMULATION_WAITMS_VALUE = 1

Define LCD_LINES = 2
Define LCD_CHARS = 16
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 2
Define LCD_RWREG = 0
Define LCD_RWBIT = 0
Define LCD_EREG = PORTB
Define LCD_EBIT = 3
Define LCD_READ_BUSY_FLAG = 0
Lcdinit 0

Define 1WIRE_REG = PORTB
Define 1WIRE_BIT = 1

Dim finish As Bit
Dim sign As Bit
Dim temp As Word
Symbol led = PORTC.2

led = 1
WaitMs 1000
led = 0

loop:
1wireInit
1wireSendByte 0xcc, 0x44
WaitMs 1000

loop1:
1wireGetBit finish
If finish = 0 Then Goto loop1

1wireInit
1wireSendByte 0xcc, 0xbe
1wireGetByte temp.LB, temp.HB
Lcdcmdout LcdClear
Lcdout #temp 'raw data readout
WaitMs 2000

sign = temp.15

If sign = 1 Then
led = 1
Lcdout "-"
temp = 65535 - temp
temp = temp + 1
Endif

temp = temp / 16

Lcdout #temp

WaitMs 2000
Goto loop


****************************************************
above is the code i use for reading Ds18b20 it is give proper reading for positive temperature.
The negative temp is not shown i only get to 0 Deg C and raw data is showing 10 in ice cold water.
LED is not getting triggered, tried different DS18B20 from different suppliers.

any ideas ??

cheers
mastero
 
What do you get if you display the temp.LB and temp.HB values separately?

The result at that point may help pin down the cause of the problem.
 
sign = temp.HB
If sign = 255 Then
'led = 1
Lcdout "-"
temp = 65535 - temp
temp = temp + 1
Endif
temp = temp / 16
Lcdout #temp
SOLVED thanx
 
Last edited:
Using 255 would only work to -15'C, if that matters?
You could make it eg.
if sign > 127 then
...
That avoids confusing the bits representing temperature with the sign bits.
 
Status
Not open for further replies.

Latest threads

Back
Top