ds 18s20 or ds1821


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default ds 18s20 or ds1821

    trying to read temperature have either chip cant get good reading
    or maybe none
    have a 877a at 20 mhz using bootloader
    and have a 4.7 k pull up resistor
    listing here
    any help would be appreicated
    have tried a number of programs to no avail



    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : JACK CLEAVER *
    '* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 2/6/2007 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    @ DEVICE pic16f877a, HS_OSC, WDT_ON, PWRT_ON, LVP_OFF, PROTECT_OFF

    ' Define LCD registers and bits
    Define LCD_DREG PORTB ' Port for LCD Data
    Define LCD_DBIT 4 ' Use upper 4 bits of Port
    Define LCD_RSREG PORTB ' Port for RegisterSelect (RS) bit
    Define LCD_RSBIT 3 ' Port Pin for RS bit
    Define LCD_EREG PORTB ' Port for Enable (E) bit
    Define LCD_EBIT 2 ' Port Pin for E bit
    Define LCB_BITS 4 ' Using 4-bit bus
    Define LCD_LINES 2 ' Using 2 line Display
    Define LCD_COMMANDUS 2000 ' Command Delay (uS)
    Define LCD_DATAUS 50 ' Data Delay (uS)

    define loader_used 1


    DEFINE OSC 20

    '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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jcleaver View Post
    trying to read temperature have either chip cant get good reading
    or maybe none
    have a 877a at 20 mhz using bootloader
    and have a 4.7 k pull up resistor
    listing here
    any help would be appreicated
    have tried a number of programs to no avail
    Check that really long (300+ posts) thread in PBPro called SerIn SerOut Problems. In it, there's almost a complete example of running an DS1820.

  3. #3


    Did you find this post helpful? Yes | No

    Default ?

    ok will check
    am curious doesnt owin owout not the same?

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jcleaver View Post
    ok will check
    am curious doesnt owin owout not the same?
    I don't understand the question...

  5. #5


    Did you find this post helpful? Yes | No

    Default ?

    why are they using the serin serout commands
    trying to display temp on a lcd
    if you notice the program i copied
    the temp sensor is read and written with the owout and owin command
    cant understand what the serin function is doing is it sending the display to the pc

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jcleaver View Post
    why are they using the serin serout commands
    trying to display temp on a lcd
    if you notice the program i copied
    the temp sensor is read and written with the owout and owin command
    cant understand what the serin function is doing is it sending the display to the pc
    The other program is just an example, most likely not exactly what you need. If you read through the thread, you'll see that the program and process related to in the Serin/Serout Problem thread (in the PBPro section) is for wireless transfer of data between 2 PICs, one getting the data from a DS1820 then transmitting it, and one receiving the data and displaying it. If you read thru it all, you'll find a working model of how to read the data from the ds1820 and send it out to an LCD without worrying about the intermediate serin/serout commands.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    i have found a program thatdoes work finally i have listed it below
    problem with the others i tried must have something to do with the
    owin and owout statements timeing or something i am not knowledgeable enough to find out why perhaps someone else could explain
    here is listing of program that works all others i tried do not reflect the temperature

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : JACK CLEAVER *
    '* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 2/5/2007 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    ' Picbasic Pro program to read DS1820 1-wire temperature sensor
    ' and display temperature on LCD
    ' Define LCD registers and bits

    DEFINE LOADER_USED 1


    Define LCD_DREG PORTB ' Port for LCD Data
    Define LCD_DBIT 4 ' Use upper 4 bits of Port
    Define LCD_RSREG PORTB ' Port for RegisterSelect (RS) bit
    Define LCD_RSBIT 3 ' Port Pin for RS bit
    Define LCD_EREG PORTB ' Port for Enable (E) bit
    Define LCD_EBIT 2 ' Port Pin for E bit
    Define LCB_BITS 4 ' Using 4-bit bus
    Define LCD_LINES 2 ' Using 2 line Display
    Define LCD_COMMANDUS 2000 ' Command Delay (uS)
    Define LCD_DATAUS 50 ' Data Delay (uS)




    DEFINE OSC 20


    ' Allocate variables
    command var byte ' Storage for command
    i var byte ' Storage for loop counter
    temp var word ' Storage for temperature
    DQ var PORTC.2 ' Alias DS1820 data pin
    DQ_DIR var TRISC.2 ' Alias DS1820 data direction pin
    FTEMP VAR WORD

    ADCON1 = 7 ' Set PORTA and PORTE to digital

    Low PORTE.2 ' LCD R/W line low (W)
    Pause 100 ' Wait for LCD to start

    Lcdout $fe, 1, "Temp in degrees C" ' Display sign-on message
    PAUSE 1000
    LCDOUT $FE,1
    PAUSE 50

    ' Mainloop to read the temperature and display on LCD
    mainloop:
    Gosub init1820 ' Init the DS1820

    command = $cc ' Issue Skip ROM command
    Gosub write1820

    command = $44 ' Start temperature conversion
    Gosub write1820

    Pause 2000 ' Wait 2 seconds for conversion to complete

    Gosub init1820 ' Do another init

    command = $cc ' Issue Skip ROM command
    Gosub write1820

    command = $be ' Read the temperature
    Gosub write1820
    Gosub read1820

    ' Display the decimal temperature

    Lcdout $fe, 1, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
    PAUSE 1000
    LCDOUT $FE,1
    PAUSE 50
    FTEMP = (180/100 * TEMP) +32
    LCDOUT $FE,1, " ",DEC FTEMP, " DEGREES F"
    PAUSE 1000
    LCDOUT $FE, 1
    PAUSE 50

    Goto mainloop ' Do it forever


    ' Initialize DS1820 and check for presence
    init1820:
    Low DQ ' Set the data pin low to init
    Pauseus 500 ' Wait > 480us
    DQ_DIR = 1 ' Release data pin (set to input for high)

    Pauseus 100 ' Wait > 60us
    If DQ = 1 Then
    Lcdout $fe, 1, "DS1820 not present"
    Pause 500
    Goto mainloop ' Try again
    Endif
    Pauseus 400 ' Wait for end of presence pulse
    Return


    ' Write "command" byte to the DS1820
    write1820:
    For i = 1 to 8 ' 8 bits to a byte
    If command.0 = 0 Then
    Gosub write0 ' Write a 0 bit
    Else
    Gosub write1 ' Write a 1 bit
    Endif
    command = command >> 1 ' Shift to next bit
    Next i
    Return

    ' Write a 0 bit to the DS1820
    write0:
    Low DQ
    Pauseus 60 ' Low for > 60us for 0
    DQ_DIR = 1 ' Release data pin (set to input for high)
    Return

    ' Write a 1 bit to the DS1820
    write1:
    Low DQ ' Low for < 15us for 1
    @ nop ' Delay 1us at 4MHz
    DQ_DIR = 1 ' Release data pin (set to input for high)
    Pauseus 60 ' Use up rest of time slot
    Return


    ' Read temperature from the DS1820
    read1820:
    For i = 1 to 16 ' 16 bits to a word
    temp = temp >> 1 ' Shift down bits
    Gosub readbit ' Get the bit to the top of temp
    Next i
    Return

    ' Read a bit from the DS1820
    readbit:
    temp.15 = 1 ' Preset read bit to 1
    Low DQ ' Start the time slot
    @ nop ' Delay 1us at 4MHz
    DQ_DIR = 1 ' Release data pin (set to input for high)
    If DQ = 0 Then
    temp.15 = 0 ' Set bit to 0
    Endif
    Pauseus 60 ' Wait out rest of time slot
    Return

    End

Similar Threads

  1. Help with DS1821 1-wire Thermometer
    By sanpic in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 6th November 2008, 07:59
  2. Need help PIC 18F2550 with DS 1302
    By christina86 in forum mel PIC BASIC
    Replies: 1
    Last Post: - 28th December 2007, 01:05
  3. ds 1307 revisted
    By jcleaver in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th February 2007, 14:10
  4. ds 1307
    By jcleaver in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 5th February 2007, 16:09
  5. DS 1620 Code example?
    By G-R-C in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 27th September 2006, 02:45

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