Please help with code for DS18B20


Closed Thread
Results 1 to 40 of 110

Hybrid View

  1. #1
    Gabestarting's Avatar
    Gabestarting Guest


    Did you find this post helpful? Yes | No

    Default

    Sorry, reading the text again i observed that i have the right sensor, i was lucky...So, the thermostat works fine, i am happy for the bas-file, however it is easier to understand than assembler. I made the circuit on a stripboard. Have a nice evening!

  2. #2
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    I want now to try to read the temperature with two sensors DS18B20 ; one for IN and other for OUT. It is possible ? How can I display both temperatures ?
    Help, please !

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Fratello

    some homework to do for you ...

    take the DS18B20 Datasheet out, and look at :

    1) How to get the device ID
    2) How to address the device with it's ID

    Buuuuuut, I do think ALL the answers you look for already are posted on this Maaarrrrrvellous Forum !!!

    It's called SEARCH Function ...

    Alain

    PS: HELP Function momentarily out of use : New Year update ... lol
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    I try to read the serial number of my DS18B20 sensor with this code :

    TRISA= %11110000 ' RA0..3=Outputs RA4=Input
    TRISB= %00000111 ' RB0..RB2=Inputs, RB3..RB7=Outputs
    CMCON=7 ' Disable comparators

    DEFINE LCD_DREG PORTB ' LCD on port B
    DEFINE LCD_DBIT 4 ' Data bits B4..B7
    DEFINE LCD_RSREG PORTA ' RS on PORTA
    DEFINE LCD_RSBIT 1 ' RS on A1
    DEFINE LCD_EREG PORTA ' E on PORTA
    DEFINE LCD_EBIT 0 ' E on A0
    DEFINE LCD_BITS 4 ' LCD 4 bit mode
    DEFINE LCD_LINES 2 ' 2 line LCD display

    DQ Var PORTA.4 ' One-wire data pin
    i Var Byte
    Temp Var Byte
    ReadRom Con $33

    Pause 500
    LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off
    Pause 250

    Main

    OWOut DQ, 1, [ReadRom]
    for i = 0 to 7
    OWIn DQ, 0, [Temp]
    LcdOut $FE, $80, Hex Temp
    Next
    LcdOut $FE, $14
    LcdOut $FE, $14
    Pause 1000
    GoTo Main


    but on display appears only "A7". What I do wrong ? Thanks !

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Code:
    LcdOut $FE, $80, Hex Temp
    The $80 moves the cursor to Line1 Column1, and it overwrites the previous values on each loop. All you see is the last loop.
    <br>
    DT

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    Per aspera ad astra !!!!
    I write another code :

    DQ Var PORTA.4 ' One-wire data pin
    i Var Byte
    Temp Var Byte
    ReadRom Con $33
    ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code


    Begin:
    PAUSE 500 ' Wait .5 second
    LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off

    Start_Convert
    OWOUT DQ, 1, [$33] ' Issue Read ROM command

    ID_Loop:
    OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
    for i = 0 to 7
    LcdOut HEX ID[i]
    next i
    END



    Now I have on display : 28CAC648100A7
    I think now it is correct. Can You confirm ? Thanks !

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Fratello

    Looks fine

    my DS shows 7A00000190DF64

    read you soon

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

Members who have read this thread : 3

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