I am a newbie to this forum.
I have DS18S20 displaying problem. My system uses LCD (16x2, Hitachi 44780 controller-based SC1602BSLB), PBP v.2.45 and 16F877 with 4MHz ceralock. At a room temp. of 19 degrees C (by mercury thermometer), for example, I get 155.18 degrees C on LCD. If I touch DS18S20 chip with my fingers, it gradually rises up to about 220.xx degrees C. If the chip is heated by soldering iron, when the display reaches to somewhere around 650.xx degrees C, it suddenly drops to 0.xx degrees C and begins to rise again. I cannot solve this wrong-temperature displaying problem. I need your help. Pin connections and the codes I used are as follows. Thank you.
'Pin 1 - Vdd (+5V)
'Pin 2 - Vss (GND)
'Pin 3 - Vo
'Pin 4 - RS to RD2 (PIC)
'Pin 5 - R/W (GND)
'Pin 6 - E to RD3 (PIC)
'Pin 11 - RD4 (PIC)
'Pin 12 - RD5 (PIC)
'Pin 13 - RD6 (PIC)
'Pin 14 - RD7 (PIC)
'DS18S20 - DQ pin to RC2(PIC), DQ pin to Vdd pin via 4.7 k r, GND pin to GND
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTD
Define LCD_RSBIT 2
Define LCD_EREG PORTD
Define LCD_EBIT 3
Define LCD_BITS 4
Define LCD_LINES 2
DQ var PORTC.2
temperature Var Word
count_remain Var Byte
count_per_c Var Byte
ADCON1 = 7
pause 100
Main: OWOut DQ,1,[$CC,$44]
Waitloop: OWIn DQ,4,[count_remain]
If count_remain = 0 Then Waitloop
OWOut DQ,1,[$CC,$BE]
OWIn DQ,0,[temperature.LOWBYTE,temperature.HIGHBYTE,Skip 4,count_remain,count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100)/count_per_c)
Lcdout $fe,1,DEC (temperature/100),".",DEC2 temperature," C"
Pause 1000
Goto Main
End
'Shozo Kanamori (Tokyo)
Bookmarks