onewire.bas & DS18B20 - reading shows 10x greater temperature!


Closed Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,122

    Default onewire.bas & DS18B20 - reading shows 10x greater temperature!

    Hello.

    I've taken the code from onewire.bas and modified only LCD port assignment code:

    Code:
    ' Name        : ONEWIRE.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6
    ' Assembler   : PM or MPASM
    ' Target PIC  : 40-pin 16F877A or similar
    ' Hardware    : Lab-X1
    ' Oscillator  : 4MHz external
    ' Keywords    : LCDOUT, OWIN, OWOUT
    ' Description : PICBASIC PRO program to demonstrate 1-wire temperature
    ' display with LAB-X1 and DS1820 1-wire temp sensor.
    '
    
    temperature  Var Word       ' Temperature storage
    count_remain Var Byte       ' Count remaining
    count_per_c  Var Byte       ' Count per degree C
    
    DQ Var PORTC.0              ' One-wire data pin
    
    ' Define LCD registers and bits
    Include "modedefs.bas"  ' Include serial modes
    ADCON1=%00000110 'CONFIGURE PORT A AS DIGITAL
    'DEFINES FOR LCD PORTS
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4 
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 1500
    DEFINE LCD_DATAUS 44 
    
      ' ADCON1 = 7                    ' Set PORTA and PORTE to digital
       'Low PORTE.2                   ' LCD R/W line low (W)
    
    mainloop:
       OWOut DQ, 1, [$CC, $44]       ' Start temperature conversion
    
    waitloop:
       OWIn DQ, 4, [count_remain]    ' Check for still busy converting
       If count_remain = 0 Then waitloop
    
       OWOut DQ, 1, [$CC, $BE]       ' Read the temperature
       OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
    
       ' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
       temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
       Lcdout $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
    
       ' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
       temperature = (temperature */ 461) + 3200
       Lcdout $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"
    
       Pause 1000                    ' Display about once a second
       Goto mainloop                 ' Do it forever
    
       End
    The problem is, that code works, but displays 10x larger temperature, and temperature is also incorrect - the error rate increases as temperature increases and for 70C error is 10C, it displays 60C (for 35C error is 5C, displays 30C and so on).

    What might be the reason?

    I've tried different DS18B20's, in TO or SOIC package, everyone has the same problem!

  2. #2
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: onewire.bas & DS18B20 - reading shows 10x greater temperature!

    Silly me.

    Code is for 1820, I have 18B20, had to use different code.

Similar Threads

  1. Reading temperature using multi DS18B20
    By KVLV in forum Code Examples
    Replies: 16
    Last Post: - 3rd November 2017, 19:48
  2. ds18b20 not reading on 16f676
    By revelator in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd April 2009, 00:20
  3. Ds1820S & onewire.bas
    By Lotondo in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th May 2006, 21:37
  4. Reading 5 DS18B20 Problem
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2005, 20:51
  5. Serout "onewire.bas"
    By puru in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th July 2005, 00:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts