PDA

View Full Version : Negative temp DS1820



Fredrick
- 19th January 2008, 02:59
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.. ;)



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

Pic_User
- 19th January 2008, 03:20
Hi Fredrick,

This might help:

Give this a try...
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>


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-

Fredrick
- 19th January 2008, 03:43
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... :)

skimask
- 19th January 2008, 06:29
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?