Hi again;
I allready found it out.
Here is the code:
Code:
'****************************************************************
'* Name : TESTE DS1820.BAS *
'* Author : GADELHAS *
'* Notice : Copyright (c) *
'* : All Rights Reserved *
'* Date : 23-04-2011 *
'* Version : 1.0 *
'* Notes : BreadBoard + EASYPICV6 *
'* : PIC16F877A *
'****************************************************************
DEFINE OSC 20
@ __config _HS_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF & _BODEN_OFF & _PWRTE_OFF
' VARIABLES
' ====================================================================
TEMPC Var Word
OFFSETTEMP VAR BYTE
SIGN var bit
FLAG VAR BYTE
temp var byte
' PINOUT 1 = IN; 0 = OUT
' ====================================================================
'76543210
TRISA = %00000000
TRISB = %00000000
TRISC = %10010000
TRISD = %00001100
TRISE = %00000000
ADCON1 = 7
' ALIAS
' ====================================================================
LED VAR PORTB.7
BMENOS var PORTD.2
BMAIS var PORTD.3
BMENU VAR PORTC.4
OUT Var PORTC.2
DQ VAR PORTE.2
' DEFINITIONS
' ====================================================================
DEFINE LCD_DREG PORTB ' LCD Data bits on PORTB
DEFINE LCD_DBIT 0 ' PORTB starting address
DEFINE LCD_RSREG PORTB ' LCD RS bit on PORTB
DEFINE LCD_RSBIT 4 ' LCD RS bit address
DEFINE LCD_EREG PORTB ' LCD E bit on PORTB
DEFINE LCD_EBIT 5 ' LCD E bit address
DEFINE LCD_BITS 4 ' LCD in 4-bit mode
DEFINE LCD_LINES 2 ' LCD has 2 rows
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us
' MAIN
' ====================================================================
PAUSE 100
INICIO: '01234567890123456789
Lcdout $fe, 1, " DS1820 Teste "
Lcdout $fe, $C0," HUGO OLIVEIRA "
Pause 1000
MAIN:
if Bmenu = 0 then
Pause 200
goto MENU
endif
gosub SENSOR
IF SIGN=1 THEN
Lcdout $fe, $C0, "Temp: -",DEC ABS (TEMPC/10), 223,"C "
else
Lcdout $fe, $C0, "Temp: ",DEC ABS (TEMPC/10), 223,"C "
endif
Goto MAIN
' BUTTON ROUTINE
' ====================================================================
MENU:
flag=1
while flag <> 0
pause 100
if flag = 1 then
Lcdout $fe, $1, "Menu 01-OffSet Temp."
if OFFSETTEMP.7 = 0 THEN
Lcdout $fe, $C0,"OffSet: ", DEC abs(OFFSETTEMP)
ELSE
Lcdout $fe, $C0,"OffSet: -", DEC abs(OFFSETTEMP)
ENDIF
gosub PLUSBUTTON
gosub MINUSBUTTON
endif
if Bmenu =0 then
pause 200
if flag = 1 then
flag =0
else
flag = flag + 1
endif
endif
wend
GOTO MAIN
PLUSBUTTON:
if Bmais = 0 then
pause 200
if flag = 1 then
if OFFSETTEMP = 5 then
OFFSETTEMP = 5
else
OFFSETTEMP=OFFSETTEMP + 1
endif
endif
ENDIF
RETURN
MINUSBUTTON:
if BMENOS = 0 then
pause 200
if flag = 1 then
if OFFSETTEMP = 251 then
OFFSETTEMP = 251
else
OFFSETTEMP=OFFSETTEMP - 1
endif
endif
ENDIF
RETURN
' TEMPERATURE ROUTINE
' ====================================================================
SENSOR:
owout DQ,1,[$CC, $44]
Pause 200
owout DQ,1,[$CC, $BE]
OWIn DQ, 2, [TempC.byte0, TempC.byte1]
temp=abs(OFFSETTEMP)
IF OFFSETTEMP.7=1 then
temp =(temp<<1)
tempc = TEMPC-temp
else
temp =(temp<<1)
tempc = TEMPC+temp
ENDIF
sign = tempc.15
TempC = ABS(TempC)
TempC =(TempC>>1)*10 + (TempC.0 * 5)
return
END
In the aquisition and temperature conversion routine i change from this:
Code:
SENSOR:
owout DQ,1,[$CC, $44]
Pause 200
owout DQ,1,[$CC, $BE]
OWIn DQ, 2, [TempC.byte0, TempC.byte1]
sign = tempc.15
TempC = ABS(TempC)
TempC =(TempC>>1)*10 + (TempC.0 * 5)
return
to this;
Code:
SENSOR:
owout DQ,1,[$CC, $44]
Pause 200
owout DQ,1,[$CC, $BE]
OWIn DQ, 2, [TempC.byte0, TempC.byte1]
temp=abs(OFFSETTEMP)
IF OFFSETTEMP.7=1 then
temp =(temp<<1)
tempc = TEMPC-temp
else
temp =(temp<<1)
tempc = TEMPC+temp
ENDIF
sign = tempc.15
TempC = ABS(TempC)
TempC =(TempC>>1)*10 + (TempC.0 * 5)
return
END
The new code and hex file is attached if some one want to give it a try.
Thank you.
Bookmarks