DS1820 display with 7-seg 4 digits


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    May 2005
    Posts
    70

    Default DS1820 display with 7-seg 4 digits

    Hi every one i would lioke to share with my project.
    I did make temperature display and show on 7-seg.[ 45.5C ]

    Code:

    Define LOADER_USED 1
    DEFINE OSC 4
    @ Device pic16F877A, xt_OSC, BOD_OFF, PWRT_ON, WDT_OFF, PROTECT_OFF 'WRT_On

    Segments Var PORTC
    Digits Var PORTD

    i Var Byte
    n Var Byte
    Value Var Word

    ' Allocate variables
    command var byte ' Storage for command
    J var byte ' Storage for loop counter
    temp var word ' Storage for temperature
    T VAR WORD
    DQ var PORTd.4 ' Alias DS1820 data pin
    DQ_DIR var TRISd.4 ' Alias DS1820 data direction pin
    read_done var byte
    Lastdata var word


    TRISc = $00 ' Set segment pins to output
    TRISd = $f0 ' Set digit pins to output
    TrisB = $00
    Portb = $00
    portd = $ff

    OPTION_REG = $50 ' Set TMR0 configuration 1:64
    INTCON = $A0 ' Enable TMR0 interrupts
    'On Interrupt Goto display

    'ADCON1 = 7 ' Set PORTA and PORTE to digital
    ' Lcdout $fe, 1, "Temp in degrees C" ' Display sign-on message
    'debug ====


    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 12 ' 19200 Bauds ,4 m
    'debug ====

    ' Mainloop to read the temperature and display on LCD


    mainloop:
    'goto display
    'Goto 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
    'HSEROUT ["Temp = ",dec (temp>>1),".", dec (temp.0*5)," C",13,10]
    'T = ((temp>> 1)*100)+((TEMP.0*5)*10)
    'HSEROUT ["Temp = ",dec T ,13,10]
    value = ((temp>> 1)*100)+((TEMP.0*5)*10)
    GOTO DISPLAY
    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"
    PORTC = $39
    LOW DIGITS.0
    PAUSE 150
    PORTC = $0
    Pause 150
    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
    '================== 7 seg ment display ==============================
    display:
    'value = ((temp>> 1)*100)+((TEMP.0*5)*10)

    PORTC = $39 'Show C on display
    LOW DIGITS.0
    PAUSEUS 1500
    PORTC = $0

    'value = 125
    For i = 1 To 4 ' Loop through 4 digits

    n = Value Dig i ' Get digit to display

    ' Gosub display1 ' Display the value
    Digits = $ff

    Lookup n, [$3F, $06, $5B, $4F, $66, $6D, $7D, $07, $7F, $6F,_
    $77, $7C, $39, $5E, $79, $71, $0FF], Segments

    If i = 2 then segments = segments + 128 'Digit 2 show dot

    Digits = ~Dcd i

    NEXT I
    goto mainloop


    End
    Attached Images Attached Images  

  2. #2
    Join Date
    Jun 2006
    Location
    California
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Centigrade/Fahrenheit

    So do you have code for Fahrenheit ??

  3. #3
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Just convert Centigrade to Farenheit

    C/5*9+32=F

    although to maintain a bit more accuaracy with PBP integer maths I would do

    C*9/5+32=F

    then display the result followed by "F" instead of "C"
    Keith

    www.diyha.co.uk
    www.kat5.tv

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Why the octal buffer?

    Hello chai98a,

    Why did you use the 74HC541 octal buffer?

    Is it because of a power issue between PIC and display?
    Roger

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Hello chai98a,

    Why did you use the 74HC541 octal buffer?

    Is it because of a power issue between PIC and display?
    I had asked the same question before.
    AND I think the answer was that he had seen a design with 74HC541 somewhere. That was why.


    -------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Sep 2007
    Location
    philippines
    Posts
    4


    Did you find this post helpful? Yes | No

    Default 7-segment display counter

    hi!!!
    im new in pic programming.. please give me sample codes for a circuit that counts from 0 - 99 (2 seven segment display) when a sensor is triggered. and alarms if the sensor is not triggered or idle for about 10 seconds.. thanks!!

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


    Did you find this post helpful? Yes | No

    Talking

    Hi, Gimo

    That's not sample you request, but a complete application ...

    How much do you offer ???

    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 " !!!
    *****************************************

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Gimo

    That's not sample you request, but a complete application ...

    How much do you offer ???

    Alain

    Hey gimo,

    I will accept 1 buck less then what Alain accepts.

    That is, of course, IF the OFFER is > 1 buck.


    ---------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  9. #9
    Join Date
    Sep 2007
    Location
    philippines
    Posts
    4


    Did you find this post helpful? Yes | No

    Wink

    hahaha... just give it for free please???

  10. #10
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    How can you get the DS1820 and LCD to display actual 10ths of a degree?
    My code I use for displaying the results of the conversion is
    Code:
     LCDOUT $FE,$C0,"Temp", $fe, $C7, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C"
    but it only seems to measure in 0.5degree steps not 0.1 degree steps
    so it will never show room temperature as 19.7șC it will instead show 19.5șC is there a way to fix this?
    Rest of the conversion code is
    Code:
    ' Initialize DS1820 and check to see IF I was stupid enough to forget the DS1820
    init1820:
            Low DQ                  ' Set the data pin low to init
            Pauseus 500             ' Wait > 500us
            DQ_DIR = 1              ' Release data pin (set to input for high)
    
            Pauseus 100             ' Wait > 100us
            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
    Also:
    How can you use 2 DS1820's and have them display the results on 2 different lines of the LCD, I know they are 1wire and should work fine, but how do you talk to each one individually and get the results from each one?
    Quote Originally Posted by gimo View Post
    hi!!!
    im new in pic programming.. please give me sample codes for a circuit that counts from 0 - 99 (2 seven segment display) when a sensor is triggered. and alarms if the sensor is not triggered or idle for about 10 seconds.. thanks!!
    I'm a newbie just teaching myself about Pic's and programming, mainly by using snippets of other people's code and changing a few things to see what happens and try and figure out how to make it work
    but the request you made can be found in numerous places, loads of sample codes contain that, and come on, its not that hard to work out, even for a wanna be blonde!
    Last edited by karenhornby; - 10th April 2008 at 11:00.

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Karen

    AS the DS18x20 has a +/- .5 degrees precision ... is it useful to show the tenths of degree ???

    Now, take the DS 1820 Datasheet ... How much degrees for 1 Count ???

    Are you able to show the 1/10 degree ???

    ( Check if your DS 1820 is a DS1820 , a DS18B20, a DS 18S20 ??? )

    Take the DS 18B20 Datasheet ... How much degrees for 1 Count ??? Can you read .1 degree NOW ???


    NOW, for 2 DS 1820 ... Two solutions :

    1) each has its DATA PIN
    2) you have to address them by using their DEV i.d. before sending them commands ...

    Make your choice ...

    Alain
    Last edited by Acetronics2; - 10th April 2008 at 13:16.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  12. #12
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    Thanks ,
    but I've never programmed anything before and have only heard of stamp not used it.
    I'm just teaching myself by trial and error as I go along.
    hmm I can see some research coming up on how to address each device by device ID and how I find the device id to start with!

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


    Did you find this post helpful? Yes | No

    Lightbulb

    Have a look here ...

    http://www.rentron.com/PicBasic1.htm

    Bottom left of the page ... just the other side you went from ...

    And Thanks to Bruce !

    Alain
    Last edited by Acetronics2; - 10th April 2008 at 13:15.
    ************************************************** ***********************
    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. 7 Segment Displays and MAX7219
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 31st October 2010, 18:30
  2. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  3. Big 7 seg LED display
    By shahidali55 in forum General
    Replies: 31
    Last Post: - 12th December 2007, 05:13
  4. Time display on 7-seg 4 digits
    By chai98a in forum Code Examples
    Replies: 12
    Last Post: - 5th March 2007, 07:24
  5. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 20:25

Members who have read this thread : 2

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