Code:
@ __config _INTOSC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON
DEFINE OSC 4
CMCON = 7
VRCON = 0
INTCON = 0
DQ VAR PORTA.4
CLEAR
SEGDEF VAR BYTE[3]
Value VAR WORD
Idx VAR BYTE
Temp VAR BYTE
digitloop VAR BYTE
Blanking VAR BIT
Temperature Var Word
TempC Var Word
I Var Byte
Sign Var Word
Float Var Word
V Var Word
Dummy Var Byte
Busy Var Bit
DS18B20_12bit CON %01111111 ' 750ms, 0.0625°C
TrisB=0 ' Make PortB outputs
TrisA.0=0:TrisA.1=0:TrisA.2=0 ' Make only the specific bits of PortA outputs
TrisA.3=0:TrisA.4=1
PortA=0:PortB=0 ' Clear PortB and PortA
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _DISP, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
TRISA = 0
TRISB = 0
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
T1CON = $1
' Init Sensor 1
OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit]
OWOut DQ, 1, [$CC, $48] ' Start temperature conversion
OWOut DQ, 1, [$CC, $B8]
OWOut DQ, 1, [$CC, $BE]
Pause 50
OWIn DQ, 2, [temperature.byte0, temperature.byte1]
Main:
' Start temp.conv.Sensor1
OWOut DQ, 1, [$CC, $44]
OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 2, [temperature.byte0, temperature.byte1]
If Temperature.15 then
Temperature= ~Temperature +1
Sign = 1
Endif
Dummy = 625 * Temperature
TempC = DIV32 10
TempC = (Temperature & $7FF) >> 4
Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
Temperature = TempC*100 + Float
If Sign=1 then
V= 10000 - Temperature
else
V= 10000 + Temperature
EndIf
If V >= 10000 then
Temperature=V-10000
sign = " "
else
Temperature=10000-V
sign = "-"
EndIf
FOR Value = 0 TO 9999
GOSUB SetDisp
PAUSE 500
NEXT Value
GOTO Main
'---[Set 7-seg patterns to WORD value]------------------------------------------
SetDisp:
Blanking = 1
FOR Idx = 3 to 0 STEP -1
Temp = Value DIG Idx
IF (Blanking AND Temp != 0) OR Idx = 0 THEN Blanking = 0
IF Blanking THEN
Temp = 0
ELSE
LookUp Temp,[132,175,193,137,170,152,144,143,128,136,210,251],Temp
ENDIF
SEGDEF(Idx) = Temp
NEXT Idx
RETURN
'---[TMR1 - interrupt handler]--------------------------------------------------
DISP:
T1CON.0 = 0 ; stop timer
TMR1H = %11111100
TMR1L = %00011111
T1CON.0 = 1 ; restart timer
PORTA = %1111 ; turn off all digits to prevent ghosting
PORTB = SEGDEF(digitloop) ; put segment pattern to pin
PORTA = ~(DCD digitloop) ; turn on the digit
digitloop = digitloop + 1
IF digitloop = 4 then digitloop = 0
@ INT_RETURN
...but where I must put the value of temperature ?! Any advice, please ? Thanks !
Bookmarks