Negative temp DS1820


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187

    Default Negative temp DS1820

    How do i modify this code so it will show negative temperatures to?

    I have been searching the forum but i canīt get it to work or is to dumb to understand..

    Code:
    DEFINE OSC 20
    DEFINE LCD_DREG PORTA       'Set LCD Data port
    DEFINE LCD_DBIT 0           'Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTA      'Set LCD Register Select port
    DEFINE LCD_RSBIT 4          'Set LCD Register Select bit
    DEFINE LCD_EREG PORTB       'Set LCD Enable port
    DEFINE LCD_EBIT 3           'Set LCD Enable bit
    DEFINE LCD_BITS 4           'Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2          'Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2000   'Set command delay time in us
    DEFINE LCD_DATAUS 100        'Set data delay time in us
    
    ADCON1 = 7   ' Set PORTA and PORTE to digital
    DQ	Var	PORTB.7  '1820 Datapin
    
    Temperature Var	Word			' Temperature storage
    Count_remain Var Byte			' Count remaining
    Count_per_c Var	Byte			' Count per degree C
    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]
        
        temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
        
        Lcdout $fe, 1
        LCDOut $fe, $c0, DEC(Temperature / 100), ".", DEC2 temperature, " C"
    
        Goto mainloop

  2. #2
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile See this post...

    Hi Fredrick,

    This might help:
    Quote Originally Posted by Darrel Taylor View Post
    Give this a try...
    Code:
    Sign  VAR  BIT
    TempC VAR  WORD
    
    ; read DS1820 here
    
    Sign = TempC.15
    TempC = ABS(TempC)
    TempC =(TempC>>1)*10 + (TempC.0 * 5)
    IF Sign then LCDOUT "-"
    LCDOUT dec (TempC/10),".",dec TempC//10
    <br>
    Quote Originally Posted by sayzer View Post
    It is finally working now for the negative values.

    I did not have this TempC = ABS(TempC) before TempC =(TempC>>1)*10 + (TempC.0 * 5)

    But, now I get correct values.

    Thanks a lot Darrel.
    Regards.
    http://www.picbasic.co.uk/forum/showthread.php?t=4820

    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  3. #3
    Join Date
    Jan 2008
    Location
    Sweden
    Posts
    187


    Did you find this post helpful? Yes | No

    Default

    How do i import the in my code?

    When iīm trying to import that my display gets crasy, but it can have to do whit my display so i need the full working code so i know if its my OLED or my code that does it..

    I have som problem with my OLED display as u can read in another thread

    EDIT: It works now...
    Last edited by Fredrick; - 19th January 2008 at 03:53.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Fredrick View Post
    How do i import the in my code?

    When iīm trying to import that my display gets crasy, but it can have to do whit my display so i need the full working code so i know if its my OLED or my code that does it..

    I have som problem with my OLED display as u can read in another thread

    EDIT: It works now...
    Having all sorts of problems with that old pirated copy of PBP 2.45 aren't ya?

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 11:45
  2. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  3. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  4. DS1820 display with 7-seg 4 digits
    By chai98a in forum Code Examples
    Replies: 12
    Last Post: - 10th April 2008, 13:12
  5. DS1820 again
    By paxmowa in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th January 2006, 14:49

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