PDA

View Full Version : ds18b20 not reading on 16f676



revelator
- 1st April 2009, 22:14
Hi, first post here ...thanks for this great forum.

At this point I have regressed from OK. to worse in trying to read the dallas 18b20 with external supply (5V from the ME Labs X2). Frustration is growing. (hence the post)..but don't want to give up.

With PBP 2.4 and all updates I was able to read the initial startup temp
84 deg C and serial numbers, family code, etc. using Bruce's avail code from Rentron. However, I never got to read any other temp other than the startup. I've tried 20 MHZ oscillator (replaced the 4.0 mhz) with same results. Tried two 4.7k R's in parallel to see if pullup was weak due to wire length (~ 3 ft.), then got nothing. Then decided to upgrade to version 2.5. Now I'm not reading anything but zeros on the fam code, ser number. Tried running the latest 2.5 patch from ME Labs and same results. Now I'm reading nothing as if it does not go beyond the convert sub. Any ideas? What else can I try?

Below is the section of the the code that was partially working (omitted the below zero degrees ) with slight changes for 16 x 2 line serial LCD

----------------------------------------------------------

'DEFINE LOADER_USED 1 ' Boot-Loader is being used
DEFINE OSC 20 ' We're using a 20MHz oscillator
'DEFINE OSC 4 ' We're using a 4MHz oscillator

Comm_Pin VAR PortC.0 ' One-wire Data-Pin "DQ" on PortC.0
Busy VAR BIT ' Busy Status-Bit
R_Temp VAR WORD ' RAW Temperature readings
Lo_ByteR var R_Temp.Byte0
Hi_ByteR var R_Temp.Byte1
TempC VAR WORD ' Temp in deg C
TempF VAR WORD ' Temp in deg F
Float VAR WORD ' Holds remainder for + temp C display
Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Real_Cold CON 1 ' Define Real_Cold = 1
BAUD CON 16468 ' N9600 for serial LCD
DISP VAR PortB.0 ' Pin to drive serial LCD
Deg CON 223 ' Data to display Deg ° symbol
CLR CON 1 ' CLR LCD command
LINE1 CON 128 ' LCD line #1
LINE2 CON 192 ' LCD line #2
INS CON 254 ' LCD command mode parameter
Sign VAR BYTE ' +/- sign for temp display
Dummy VAR BYTE ' Dummy for Div32


Pause 500
SEROUT2 DISP,BAUD, [INS,CLR]
SerOut2 DISP, BAUD, ["My display"] ' Display " whatever"
Pause 1000 ' Wait .5 second

Start_Convert:

OWOUT Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion

Wait_Up:

OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
OWOUT Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
OWIN Comm_Pin, 2, [Lo_ByteR, Hi_ByteR]' Read two bytes / end comms
SEROUT2 DISP,BAUD, [INS,CLR]
GOSUB Convert_Temp
pause 500
GOTO Start_Convert

Convert_Temp: ' +32.0 to +257 F
IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
Dummy = 1125 * R_Temp
TempF = DIV32 100
IF TempF >6795 THEN ' Over 99.5 deg F..?
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 4,_
DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ELSE
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 3,_
DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ENDIF
pause 500
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((Lo_ByteR & $0F) * 625) ' Lower 4-bits of result * 625
'SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C "]
'changed IBIN to display 12 bits only due to display limit of 16
SEROUT2 DISP,BAUD, [INS,LINE2, "R=", IBIN12 R_Temp]
pause 2000
RETURN

Darrel Taylor
- 1st April 2009, 23:03
Some day everyone will know this.
But I guess by then, most of them will have forgotten it. :)


ANSEL = 0
CMCON = 7

Also, the 16F676 doesn't have a PORTB.0
<br>

revelator
- 2nd April 2009, 00:20
My bad Darrel! I really meant a 16f876 and this one has the RB0/INT pin