gadelhas
- 23rd April 2011, 03:09
Hi everyone once again;
I made a program to read a DS1820 showing positive and negative temperatures. I found a piece of code in this forum to handle that, and its workinf fine. Now i want to put an offset in the temperature that was readed, for instance if the sensor is at 18ºC and the OFFSETTEMP variable is 2, then the LCD shows 20ºC, if the OFFSETTEMP variable is -3 than the lcd shows 15ºC.
In the code you will see that i allready have a menu to change the OFFSETTEMP variable, however i don't know now how to interect with the temperature that i'm reading.
Attached is the Proteus file with the simulation of the code, the code, and the HEX file.
The "MENU" button its to enter the the menu, and the "+" and "-" button is to change the value of the OFFSETTEMP variable.
Can somebody give me a clue?
Here is the 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
' 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]
sign = tempc.15
TempC = ABS(TempC)
TempC =(TempC>>1)*10 + (TempC.0 * 5)
return
END
I made a program to read a DS1820 showing positive and negative temperatures. I found a piece of code in this forum to handle that, and its workinf fine. Now i want to put an offset in the temperature that was readed, for instance if the sensor is at 18ºC and the OFFSETTEMP variable is 2, then the LCD shows 20ºC, if the OFFSETTEMP variable is -3 than the lcd shows 15ºC.
In the code you will see that i allready have a menu to change the OFFSETTEMP variable, however i don't know now how to interect with the temperature that i'm reading.
Attached is the Proteus file with the simulation of the code, the code, and the HEX file.
The "MENU" button its to enter the the menu, and the "+" and "-" button is to change the value of the OFFSETTEMP variable.
Can somebody give me a clue?
Here is the 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
' 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]
sign = tempc.15
TempC = ABS(TempC)
TempC =(TempC>>1)*10 + (TempC.0 * 5)
return
END