Code:
;**********************************************************************************************
; Termo with BIG fonts
; 2 x DS18B20
; Thanks to Gusse !
; may 2011
;
; ATTENTION ON SCHEMATIC !!!
;
;**********************************************************************************************
;
; .oooO
; ( ) Oooo.
; \ ( ( )
; \_) ) /
; (_/
;
@ DEVICE pic16F648A, INTRC_OSC, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_ON, LVP_OFF, CPD_OFF, PROTECT_OFF
INCLUDE "modedefs.bas"
Define NO_CLRWDT 1
DEFINE OSC 4
TRISB = %00011100 'portB configuration 0=out 1=in
TRISA = %10100000 'portA configuration
PortA = %11100000
CMCON = 7
VRCON = 0
INTCON = 0
OPTION_REG=%00000111 'weak pullups on, TMRO prescale = 256
Lcd_DC var PortB.0
Lcd_SDA var PortA.3
Lcd_RST var PortA.4
Lcd_CLK var PortA.2
DQ var PortB.2
DQ2 VAR PORTB.3
buton var portb.4
Ts VAR BIT ' TYPE Of SPACE, variable / constante
Tc VAR byte ' TYPE Of Charater, normal / big
Ic var bit ' Inverted Char
i var Byte
j var Word
k var Byte
Tv var byte ' Tipo de Variavel que se vai receber
Nc var byte ' Numero de Carateres recebidos no Serin
PosX var Byte
PosY var Byte
Letra var Byte [9]
LetraA var byte
LetraB var byte
LcdStr var Byte [28]
Lcd_Data var Byte
Temperature Var Word bank0 : Temperature2 Var Word bank0
TempC Var Word bank0 : TempC2 Var Word bank0
Sign Var Word bank0 : Sign2 Var Word bank0
Float Var Word bank0 : Float2 Var Word bank0
V Var Word bank0 : V2 Var Word bank0
Dummy Var Byte bank0 : Dummy2 Var Byte bank0
Flag var Byte
SignBit var Flag.0
LcdReg var Byte bank0
x var Byte bank0
y var Byte bank0
Busy VAR BIT bank0
Cursor var Byte bank0
DS18B20_12bit CON %01111111 ' 750ms, 0.0625°C
DS18B20_12bit2 CON %01111111 ' 750ms, 0.0625°C
'==================================================
Low Lcd_RST
pause 100
High Lcd_RST
Low Lcd_DC
Lcd_Data= %00100001: Gosub Lcd_SentByte 'LCD EXTENDED COMMANDS
Lcd_Data= $E4 : Gosub Lcd_SentByte 'SET LCD Vop (CONTRAST)
Lcd_Data= %00000100: Gosub Lcd_SentByte 'SET TEMP COEFFICENT
Lcd_Data= %00010000: Gosub Lcd_SentByte 'LCD BIAS MODE 1:48
Lcd_Data= %00100000: Gosub Lcd_SentByte 'LCD STANDARD COMMANDS
Lcd_Data= %00001100: Gosub Lcd_SentByte 'LCD IN NORMAL MODE
Ts = 0 'Space constante
Ic = 0 'Blinking OFF
Gosub Lcd_Clear
'set contrast
Low Lcd_DC
Lcd_Data= %00100001: Gosub Lcd_SentByte 'LCD EXTENDED COMMANDS
Lcd_Data= %10100100: Gosub Lcd_SentByte 'Set Vop Register
Lcd_Data= %00100000: Gosub Lcd_SentByte 'LCD STANDARD COMMANDS
'==================================================
' 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]
' Init Sensor 2
OWOUT DQ2, 1, [$CC, $4E, 0, 0, DS18B20_12bit2]
OWOut DQ2, 1, [$CC, $48] ' Start temperature conversion
OWOut DQ2, 1, [$CC, $B8]
OWOut DQ2, 1, [$CC, $BE]
Pause 50
OWIn DQ2, 2, [temperature2.byte0, temperature2.byte1]
Pause 100
'==================================================
main:
Call BorderLine
pause 100
Part1:
' 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
Part2 :
' Start temp.conv.Sensor1
OWOut DQ2, 1, [$CC, $44]
OWOut DQ2, 1, [$CC, $BE]
OWIn DQ2, 2, [temperature2.byte0, temperature2.byte1]
If Temperature2.15 then
Temperature2= ~Temperature2 +1
Sign2 = 1
Endif
Dummy2 = 625 * Temperature2
TempC2 = DIV32 10
TempC2 = (Temperature2 & $7FF) >> 4
Float2 = ((Temperature2.Lowbyte & $0F ) * 25 )>>2
Temperature2 = TempC2*100 + Float2
If Sign2=1 then
V2= 10000 - Temperature2
else
V2= 10000 + Temperature2
EndIf
If V2 >= 10000 then
Temperature2=V2-10000
sign2 = " "
else
Temperature2=10000-V2
sign2 = "-"
EndIf
if buton = 0 then
gosub buton_on
else
gosub buton_off
endif
goto main
'==================================================
buton_on:
LcdStr(5) = 59 ' simbol for degree
LcdStr(4) = 48 + Temperature dig 1
LcdStr(3) = "."
LcdStr(2) = 48 + Temperature dig 2
if Temperature dig 3=0 then
LcdStr(1) = 32
else
LcdStr(1) = 48 + Temperature dig 3
endif
LcdStr(0) = Sign
Tc=0
Nc=6
PosX=3
PosY=2
Gosub Lcd_GotoXY : Gosub Lcd_SentString
LcdStr(5) = 59 ' simbol for degree
LcdStr(4) = 48 + Temperature2 dig 1
LcdStr(3) = "."
LcdStr(2) = 48 + Temperature2 dig 2
if Temperature2 dig 3=0 then
LcdStr(1) = 32
else
LcdStr(1) = 48 + Temperature2 dig 3
endif
LcdStr(0) = Sign2
Tc=2
Nc=6
PosX=11
PosY=3
Gosub Lcd_GotoXY : Gosub Lcd_SentString
Tc=3
Nc=6
PosX=11
PosY=4
Gosub Lcd_GotoXY : Gosub Lcd_SentString
return
'==================================================
buton_off:
LcdStr(5) = 59 ' simbol for degree
LcdStr(4) = 48 + Temperature2 dig 1
LcdStr(3) = "."
LcdStr(2) = 48 + Temperature2 dig 2
if Temperature2 dig 3=0 then
LcdStr(1) = 32
else
LcdStr(1) = 48 + Temperature2 dig 3
endif
LcdStr(0) = Sign2
Tc=0
Nc=6
PosX=3
PosY=2
Gosub Lcd_GotoXY : Gosub Lcd_SentString
LcdStr(5) = 59 ' simbol for degree
LcdStr(4) = 48 + Temperature dig 1
LcdStr(3) = "."
LcdStr(2) = 48 + Temperature dig 2
if Temperature dig 3=0 then
LcdStr(1) = 32
else
LcdStr(1) = 48 + Temperature dig 3
endif
LcdStr(0) = Sign
Tc=2
Nc=6
PosX=11
PosY=3
Gosub Lcd_GotoXY : Gosub Lcd_SentString
Tc=3
Nc=6
PosX=11
PosY=4
Gosub Lcd_GotoXY : Gosub Lcd_SentString
return
'==================================================
Lcd_Clear:
For cursor = 0 to 5
PosX=0:PosY=Cursor:Gosub Lcd_GotoXY
High Lcd_DC
For i= 1 to 84
Lcd_Data=0:Gosub Lcd_SentByte
Lcd_Data=0:Gosub Lcd_SentByte
Next i
Next cursor
Return
'==================================================
Lcd_GotoXY:
Low Lcd_DC
Lcd_Data=%01000000 | PosY :Gosub Lcd_SentByte 'Y
Lcd_Data=%10000000 | PosX :Gosub Lcd_SentByte 'X
Return
'==================================================
Lcd_SentByte:
SHiftOUT Lcd_SDA , Lcd_CLK , MSBFIRST, [ Lcd_Data ]
Return
'==================================================
Lcd_SentString:
For k=0 to Nc-1
Lcd_Data=LcdStr(k)
Gosub Lcd_SentChar
next k
Return
'==================================================
Lcd_SentChar:
Letra(0)=$00:Letra(1)=$00:Letra(2)=$00:Letra(3)=$00:Letra(4)=$00:Letra(5)=$00
SELECT CASE lcd_data
' CAPITAL LETTERS
CASE 32
Tv=1 '
CASE 42
Tv=5:Letra(0)=$14: Letra(1)=$08:Letra(2)=$3E:Letra(3)=$08: Letra(4)=$14 '*
CASE 43
;Tv=5:Letra(0)=$10: Letra(1)=$10:Letra(2)=$7C:Letra(3)=$10: Letra(4)=$10 '+
Tv=5:Letra(0)=$08: Letra(1)=$08:Letra(2)=$3E:Letra(3)=$08: Letra(4)=$08 '+
CASE 45
Tv=5:Letra(0)=$08: Letra(1)=$08:Letra(2)=$08:Letra(3)=$08: Letra(4)=$08 '-
CASE 46
;Tv=3:Letra(1)=$C0: Letra(2)=$C0 '.
Tv=1:Letra(1)=$60 : Letra(2)=$60 '.
case 47
Tv=4:Letra(0)=96 : Letra(1)=48 :Letra(2)=24 :Letra(3)=12 : Letra(4)=06 '/
CASE 48
;Tv=5:Letra(0)=$7E: Letra(1)=$A1:Letra(2)=$91:Letra(3)=$89: Letra(4)=$7E '0
Tv=5:Letra(0)=$3E: Letra(1)=$51:Letra(2)=$49:Letra(3)=$45: Letra(4)=$3E '0
CASE 49
;Tv=4:Letra(1)=$82: Letra(2)=$FF:Letra(3)=$80 '1
Tv=4:Letra(1)=$42: Letra(2)=$7F:Letra(3)=$40 '1
CASE 50
;Tv=5:Letra(0)=$86: Letra(1)=$C1:Letra(2)=$A1:Letra(3)=$91: Letra(4)=$8E '2
Tv=5:Letra(0)=$42: Letra(1)=$61:Letra(2)=$51:Letra(3)=$49: Letra(4)=$46 '2
CASE 51
;Tv=5:Letra(0)=$62: Letra(1)=$81:Letra(2)=$89:Letra(3)=$89: Letra(4)=$76 '3
Tv=5:Letra(0)=$21: Letra(1)=$41:Letra(2)=$45:Letra(3)=$4B: Letra(4)=$31 '3
CASE 52
;Tv=5:Letra(0)=$38: Letra(1)=$24:Letra(2)=$22:Letra(3)=$FF: Letra(4)=$20 '4
Tv=5:Letra(0)=$18: Letra(1)=$14:Letra(2)=$12:Letra(3)=$7F: Letra(4)=$10 '4
CASE 53
;Tv=5:Letra(0)=$4F: Letra(1)=$89:Letra(2)=$89:Letra(3)=$89: Letra(4)=$71 '5
Tv=5:Letra(0)=$27: Letra(1)=$45:Letra(2)=$45:Letra(3)=$45: Letra(4)=$39 '5
CASE 54
;Tv=5:Letra(0)=$7E: Letra(1)=$89:Letra(2)=$89:Letra(3)=$89: Letra(4)=$72 '6
Tv=5:Letra(0)=$3C: Letra(1)=$4A:Letra(2)=$49:Letra(3)=$49: Letra(4)=$30 '6
CASE 55
;Tv=5:Letra(0)=$01: Letra(1)=$E1:Letra(2)=$11:Letra(3)=$09: Letra(4)=$07 '7
Tv=5:Letra(0)=$01: Letra(1)=$71:Letra(2)=$09:Letra(3)=$05: Letra(4)=$03 '7
CASE 56
;Tv=5:Letra(0)=$76: Letra(1)=$89:Letra(2)=$89:Letra(3)=$89: Letra(4)=$76 '8
Tv=5:Letra(0)=$36: Letra(1)=$49:Letra(2)=$49:Letra(3)=$49: Letra(4)=$36 '8
CASE 57
;Tv=5:Letra(0)=$46: Letra(1)=$89:Letra(2)=$89:Letra(3)=$89: Letra(4)=$7E '9
Tv=5:Letra(0)=$06: Letra(1)=$49:Letra(2)=$49:Letra(3)=$29: Letra(4)=$1E '9
CASE 58
Tv=3:Letra(1)=$36: Letra(2)=$36 ':
CASE 59
Tv=5:Letra(0)=$02: Letra(1)=$05: Letra(2)=$32: Letra(3)=$48: Letra(4)=$48 'simbol grade
end select
High Lcd_DC
If Tc = 0 Then ' Normal Charater
'==================================================
iF Ts = 0 tHEN
j = 5 ' CONSTANTE SPACE (6)
Else
j = Tv ' VARIABLE SPACE
endif
for I=0 to j
If Ic=0 Then ' Normal Charater
ShiftOUT Lcd_SDA , Lcd_CLK , 1 , [ Letra(I)]
else ' Inverted Charater
ShiftOUT Lcd_SDA , Lcd_CLK , 1 , [ (127-Letra(I))+128 ]
endif
next I
Return
Endif ' Double Charater
'==================================================
' Tc = 1 Nothing to change 2 x 1
If Tc = 2 Then ' 1ª time of 2x2
for i = 0 to 5
LetraA = Letra(i)
LetraB.0 = LetraA.0
LetraB.1 = LetraA.0
LetraB.2 = LetraA.1
LetraB.3 = LetraA.1
LetraB.4 = LetraA.2
LetraB.5 = LetraA.2
LetraB.6 = LetraA.3
LetraB.7 = LetraA.3
Letra(i) = LetraB
next i
ENdif
If TC = 3 then ' 2ª time of 2x2
for i = 0 to 5
LetraA = Letra(i)
LetraB.0 = LetraA.4
LetraB.1 = LetraA.4
LetraB.2 = LetraA.5
LetraB.3 = LetraA.5
LetraB.4 = LetraA.6
LetraB.5 = LetraA.6
LetraB.6 = LetraA.7
LetraB.7 = LetraA.7
Letra(i) = LetraB
next i
endif
iF Ts = 0 tHEN
j = 5 ' CONSTANTE SPACE
Else
j = Tv ' VARIABLE SPACE
endif
for I=0 to j
If Ic=0 Then ' Normal Charater
ShiftOUT Lcd_SDA , Lcd_CLK , 1 , [ Letra(I), Letra(i) ]
else ' Inverted Charater
ShiftOUT Lcd_SDA , Lcd_CLK , 1 , [ (127-Letra(I))+128, (127-Letra(I))+128 ]
endif
next I
Return
BorderLine: '
'=================================== RAND 0
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000000 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$01,$01,$01,$01,_
$01,$01,$01,$01,$01,$01,$01,$01,$01,$FD,$FD,$FD,$85,$85,$FD,$FD,$79,_ 'D
$01,$01,$FD,$FD,$FD,$01,$01,$79,$FD,$FD,$85,$A5,$ED,$ED,$69,$01,$01,_ 'IG
$FD,$FD,$FD,$01,$05,$05,$05,$FD,$FD,$FD,$05,$05,$05,$01,_ 'IT
$F9,$FD,$FD,$25,$25,$FD,$FD,$F9,$01,$01,$FD,$FD,$FD,$81,$81,$81,$81,_ 'AL
$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$FF] ,LcdReg
call PrintDataLcd
next y
'=================================== RAND 1
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000001 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000001 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== RAND 2
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== RAND 3
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000011 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000011 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== RAND 4
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000100 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000100 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== JOS
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000101 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$81,$81,$81,$BF,$BF,$BF,$81,$81,$81,$80,$BF,$BF,$BF,$A9,_
$A9,$A9,$A1,$80,$BF,$BF,$BF,$89,$89,$99,$A6,$80,$BF,$BF,$BF,$82,_
$84,$82,$BF,$BF,$BF,$80,$9E,$BF,$BF,$A1,$A1,$BF,$BF,$9E,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$FF] ,LcdReg
call PrintDataLcd
next y
return
'==================================================
PrintCtrlLcd: LCD_DC = 0
PrintDataLcd: for x = 1 to 8
LCD_SDA = LcdReg.7
LCD_CLK = 1
LcdReg = LcdReg << 1
LCD_CLK = 0
next x
LCD_DC = 1
return
END ' of program
Bookmarks