MULTI DEVICE 1-WIRE TEMP MON/LOG FOR GLCD WITH DS1820/S20
MULTI DEVICE 1-WIRE TEMP MON/LOG FOR GLCD WITH DS1820/S20
this is a example of multi device 1-wire temp monitor/logger for DS1820 or DS18S20.
This program, control up to 10 devices and show the results in a GLCD and can log it on a RS232 or another device.
See the photos below:
if someone is interested I can post the source.
Seeking devices.
acquiring the first data of each device.
Show all devices and temp.
This program, control up to 10 devices and show the results in a GLCD and can log it on a RS232 or another device.
See the photos below:
if someone is interested I can post the source.
Seeking devices.
acquiring the first data of each device.
Show all devices and temp.
Working with you, for you!
MAN
MAN
Thanks Raslan, Thanks XOR;
here is the source code that drives the devices.
All project and lib's is available at ftp://www.ttelecom.com.br/pub/onewire/examples/ logmonitor.zip
here is the source code that drives the devices.
All project and lib's is available at ftp://www.ttelecom.com.br/pub/onewire/examples/ logmonitor.zip
Code: Select all
'*
'* Project name:
' Multi Device 1-Wire Temp Logger
' Copyright:
' ©Marcio Nassorri
'* Revision History:
' 08/12/2007:
' - initial release.
' * Description:
' Read the net 1-wire and show in a graphics mode
' the Temp between 1 and 10 devices.
' This application is very good to use in home service.
' we can control Temp's between 5° with resolution of 0.1°C.
' The scale modify when temperature rolls over the max or min Temp scale.
' When we start the program he seek for all devices, later he make the
' one first read to all devices comparing these temperature and get the
' min of all. This min temperature is exhibit in the graphics Temp panel
' subtracted of one. if Temp decreases below 0.5° of this Temp the scale
' is changed minus one grade. If Temp increases starting of minimal to
' max the bars will increase up to max plus 0.5°, then the scale change
' adding more one grade and so on.
' The USART was activate for this example but other types of communications
' devices can be used to get the log from devices.
' This program don't provides external events this each one do the your.
'
'
' * Test configuration:
' MCU: PIC16F877A
' Dev.Board: BIGP3 with custom processor card.
' Oscillator: XT, 4.000 MHz But others can be set.
' Ext. Modules: Ow_Delays,
' Lib_mglcd16_KS0108
' Ow_romcmd_lib
' ByteToHex
'
' SW: mikroBasic v5.0 or higher
' * NOTES:
' This program can find any device in the NET. BUT Temp, will be showing only
' for family 0x10 "Temp Sensor, DS1820 or DS18S20" and in powered mode.
' For another families a filter should be created to do this.
'
' For to do this program I need to create a new form to write on GLCD, like this
' is extremely important to use the lib Lib_mglcd16_ks0108 that work with
' GLCD_Lib. This lib have 3 useful functions for to be used.
'
' This program not manages negative temperature only positive
' from 0 to 125°C.
'
' With minor modifications this program can be adapted to others MCU.
'
'
Include "Ow_Delays"
Include "Lib_mglcd16_ks0108"
Include "Ow_romcmd_lib"
Include "ByteToHex"
'+++++++++++++++++++++++++++++++++++++++++++++++
' Set Thi and Tlo alarm for devices. In this
' case all devices will have the same alarm's
' point set.
'+++++++++++++++++++++++++++++++++++++++++++++++
Symbol THI = 29
Symbol TLO = 26
'Const _TableRes as Byte[17] = (0,1,1,2,3,
' 3,4,4,5,6,
' 6,7,7,8,9,9,0)
Const _TableRes as Byte[17] = (0,9,9,8,7, '"For Use with real device
7,6,6,5,4,
4,3,3,2,1,1,0)
Dim DS_ROM as Byte[8] absolute $20
Dim LastDiscrep as byte absolute $28
Dim txt as String[20]
Dim text as String[5]
Dim SPadArray as byte[9]
Dim DevNum as Byte
Dim K, T as Byte
Dim ScaleTop, ScaleDown as Byte
Dim MaxTemp, MinTemp,Frac_Temp as Byte
Dim AVG as byte
Dim Temp, BaseTemp as Short
Dim First_Read as Boolean
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'If your Display respond correctly to the GLCD_Fill(0) this
'routine can be removed this is only why my GLCD not
'responds correctly to this command.
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub Procedure MGLCD_Clear()
Dim K as Byte
for k = 0 to 7
GLCD_Write_Text(" ",0,k,1)
Next k
End Sub
Sub Procedure Temp_Panel()
Glcd_Line(50,60,120,60,1)
for K = 50 to 120 step 7
Glcd_Line(K,60,k,62,1)
Next K
GLCD_Line(50,60,50,5,1)
for K = 60 to 10 step -10
GLCD_Line(48,k,50,k,1)
GLCD_Dot(49,k-5,1)
Next K
MGLCD_Write_Char("°",40,1,0)
MGLCD_Write_Char("C",44,1,0)
End Sub
Sub Procedure V_Temp_Dial(Dim Temp as Short)
Dim L as Byte
Dim StrTemp as Char[4]
dec(temp)
for L = 60 to 10 step - 10
ShortToStr(Temp,StrTemp)
MGLCD_Write_Char(StrTemp[1],36,l-2,0)
MGLCD_Write_Char(StrTemp[2],40,L-2,0)
MGLCD_Write_Char(StrTemp[3],44,L-2,0)
inc(Temp)
Next L
End Sub
Sub Procedure Draw_Temp_Bar(Dim pTemp as Short, Dim pDevice, pFrac_Temp as Byte)
Dim NumBar,TempBar as Byte
TempBar = 50 - ((pTemp - BaseTemp)*10) - pFrac_Temp
If TempBar < 5 then TempBar = 5 end if
For NumBar = 54+(pDevice*7) to (54+(pDevice*7)+7)-1 step 7
GLCD_Box(NumBar-2,5,NumBar+1,TempBar-1,0)
Glcd_Box(NumBar-2,TempBar,NumBar+1,59,1)
Next NumBar
End Sub
Sub Procedure Textos()
Txt = "monitor logger"
MGLCD_Write_txt(Txt,61,0,4,0)
Txt = " Temp:"
MGLCD_Write_Txt(Txt,0,0,4,0)
GLCD_Line(0,7,32,7,1)
Txt = "max:"
MGLCD_Write_Txt(Txt,0,13,4,0)
Txt = "min:"
MGLCD_Write_Txt(Txt,0,23,4,0)
Txt = "avg:"
MGLCD_Write_Txt(Txt,0,33,4,0)
txt = "alm:"
MGLCD_Write_Txt(Txt,0,43,4,0)
Txt = "dev:"
MGLCD_Write_Txt(Txt,0,53,4,0)
Glcd_Line(32,62,32,0,1)
txt = "RS232 on"
For K = 0 to 7
MGLCD_Write_Char(Txt[k],124,0,k+1)
Next K
End Sub
Sub Procedure Delay_3_Sec()
Delay_ms(3000)
End Sub
main:
ADCON1 = 7
ADCON0 = 0
Usart_Init(9600)
Ow_Config(PORTA,5)
Glcd_Init(PORTC, 1, 0, 2, 3, 4, 5, PORTD)
Glcd_Set_Font(@Font5x7,5,7,32)
MGLCD_Clear() 'can be removed.
Glcd_Fill(0)
txt = "1-wire net"
MGLCD_Write_Txt(txt,0,0,4,0)
txt = "searching.."
MGLCD_Write_Txt(Txt,0,12,4,0)
txt ="wait.."
MGLCD_Write_Txt(txt,0,24,4,0)
GLCD_rectangle(46,0,127,63,1)
if (not Ow_PUPdetect) then
txt ="No Pull-Up Detected!"
MGLCD_Write_Txt(txt,48,0,4,3)
goto DevNotFound
end if
DevNum =0
do
if (not Ow_Search(DS_Rom, LastDiscrep, _SEARCHROM)) then
goto DevNotFound
else
Inc(DevNum)
txt ="#"
ByteToHex(Text,DevNum,0)
Strcat(txt,Text)
Strcat(txt," ")
ByteToHex(Text,DS_Rom[0],0)
Strcat(Txt,Text)
text[0] = "-"
text[1] = 0
StrCat(txt,Text)
for T = 6 to 1 step - 1
ByteToHex(Text,DS_Rom[T],0)
Strcat(txt,Text)
Next T
MGLCD_Write_Txt(txt,49,3,4,DevNum-1)
end if
loop until (LastDiscrep = 0) or (DevNum = 10)
txt ="found "
HexToStr(Text,DevNum,0)
Strcat(txt,Text)
MGLCD_Write_Txt(txt,0,43,4,0)
txt = "Device(s)."
MGLCD_Write_txt(Txt,0,56,4,0)
Delay_3_Sec()
Glcd_Fill(0)
MGLCD_Clear() 'can be removed
Temp_Panel()
Textos()
V_Temp_Dial(-4)
First_Read = TRUE
MinTemp = 125
ScaleTop = 0
ScaleDown = 125
While TRUE
LastDiscrep = 0
DevNum = 0
do
Ow_Search(Ds_Rom, LastDiscrep, _SEARCHROM)
if (not Ow_ChkCRC(DS_ROM,7)) then 'Do check in the CRC ROM_Code.
txt ="CRC Error ROM"
Inc(DevNum)
MGLCD_Write_Txt(txt,75,0,4,4)
goto NextRead
end if
Ow_ConvTemp(DS_Rom) 'issue Convert temp Command.
Ow_RCALLE2PROM(DS_ROM) 'issue recall e2prom
Ow_Match_ROM(DS_ROM) 'issue Match ROM command
Ow_ReadSPad(SPadArray) 'issue readscratchpad
if (not Ow_ChkCRC(SPadArray,8)) then 'do CRC Check
Inc(DevNum) 'increment devnum
txt = "CRC Error Spad"
MGLCD_Write_Txt(Txt,71,0,4,5) 'Show error if exists
goto Nextread 'do next read
end if
'Save Thi and TLo Here
'----------------------
If First_Read then
Ow_WriteSpad9(DS_ROM,THI,TLO) 'issue write scratchpad cmd
'and set THi and TLo
Ow_Copy_SPad(DS_ROM) 'issue copy Spad to e2prom
End If
'-----------------------
Inc(DevNum) 'increment DevNum when a device is found
K = (SpadArray[6] and $1F) 'Get fraction temp.
Temp = SpadArray[0] >> 1 'Get temp.
Frac_Temp = _TableRes[K]
If (Not First_Read) then
Draw_Temp_Bar(Temp,DevNum-1,Frac_Temp)
End If
If ScaleDown > Temp then
ScaleDown = Temp
End If
If ScaleTop < Temp then
ScaleTop = Temp
End if
If MinTemp > Temp then MinTemp = Temp end if
If MaxTemp < Temp then MaxTemp = Temp end if
If (ScaleDown < BaseTemp) and (Frac_Temp < 5) then
First_Read = TRUE
end if
If (Temp = (BaseTemp + 4)) and (Frac_Temp > 4) then
First_Read = TRUE
end if
T = false
T = Ow_ChkAlarm(Temp, SpadArray[2], SpadArray[3]) 'SW check
ByteToHex(Text,DevNum,0)
MGLCD_Write_Txt(Text,16,53,4,0)
If (Not First_Read) then
if T then
txt ="On "
MGLCD_Write_Txt(txt,16,43,4,0)
else
txt = "Off"
MGLCD_Write_Txt(Txt,16,43,4,0)
End if
End if
'Start log on USART
'I've changed the byte values into HEX-str
'but it is not necessary.
txt = "#" 'First Byte starts as #.
For K = 0 to 7 'The next 8 byte have ROM code
HexToStr(Text,DS_ROM[k],0)
strcat(txt,Text)
Next K
Usart_Write_Text(Txt) 'Write to serial
txt = ""
ByteToHex(Text,T,0) 'Alarm
strcat(Txt,Text) '
ByteToHex(Text,Temp,0) 'Temperature
strcat(Txt,text ) '
ByteToHex(text,Frac_Temp,0) 'Frac Temperature
strcat(Txt,Text) '
ByteToHex(Text,sPadArray[1],0) 'Temp sign
strcat(txt,Text) '
ByteToHex(Text,SpadArray[2],0) 'Temp THi
strcat(Txt,Text ) '
ByteToHex(Text,sPadArray[3],0) 'Temp Tlo
strcat(txt,Text ) '
ByteToHex(Text,maxtemp,0) 'Temp Max
strcat(Txt,Text ) '
ByteToHex(Text,MinTemp,0) 'Temp Min
strcat(txt,Text) '
ByteToHex(Text,DevNum-1,0) 'Device number
strcat(Txt,Text) '
Usart_Write_Text(Txt) 'Write to serial
Usart_Write(13)
Usart_Write(10)
NextRead:
loop until (LastDiscrep = 0) or (DevNum = 10)'end of loop if LastDiscrep = 0.
AVG = (MaxTemp + MinTemp) div 2 'AVG div DevNum 'calc average
'Refresh text's.
ByteToStr(AVG,Text)
MGLCD_Write_Char(Text[1],16,33,0)
MGLCD_Write_Char(Text[2],20,33,0)
MGLCD_Write_Char("°",24,33,0)
ByteToStr(MinTemp,Text)
MGLCD_Write_Char(Text[1],16,23,0)
MGLCD_Write_Char(Text[2],20,23,0)
MGLCD_Write_Char("°",24,23,0)
ByteToStr(MaxTemp,Text)
MGLCD_Write_Char(Text[1],16,13,0)
MGLCD_Write_Char(Text[2],20,13,0)
MGLCD_Write_Char("°",24,13,0)
AVG = 0
DevNum = 0
If First_Read then
If (scaleTop - BaseTemp) = 4 then
ScaleDown = BaseTemp + 1
Dec(ScaleTop)
End if
V_Temp_Dial(ScaleDown)
BaseTemp = ScaleDown
First_Read = FALSE
End if
Wend
DevNotFound:
txt ="No Device Found."
MGLCD_Write_Txt(txt,57,0,4,5)
End.
Working with you, for you!
MAN
MAN
Thank you MAN! Great project!
Charlie, look at:
ftp://www.ttelecom.com.br/mcl_lib/lib_m ... ks0108.zip
ftp://www.ttelecom.com.br/mcl_lib/lib_m ... ks0108.zip
If you have problem with login to ftp server, start from the ftp root ftp://www.ttelecom.com.br
Charlie, look at:
ftp://www.ttelecom.com.br/mcl_lib/lib_m ... ks0108.zip
ftp://www.ttelecom.com.br/mcl_lib/lib_m ... ks0108.zip
If you have problem with login to ftp server, start from the ftp root ftp://www.ttelecom.com.br
-
- Posts: 573
- Joined: 25 Apr 2006 15:39
- Location: Cape Town, South Africa
-
- Posts: 573
- Joined: 25 Apr 2006 15:39
- Location: Cape Town, South Africa
All files and lib's from MAN's ftp site:
1-wirelib_mb.zip
1-wirelib_mp.zip
1-wirelib_mc.zip
lib_mglcd16_ks0108.zip
lib_mglcd18_ks0108.zip
logmonitor.zip
http://rapidshare.com/files/54870699/MA ... r.rar.html
1-wirelib_mb.zip
1-wirelib_mp.zip
1-wirelib_mc.zip
lib_mglcd16_ks0108.zip
lib_mglcd18_ks0108.zip
logmonitor.zip
http://rapidshare.com/files/54870699/MA ... r.rar.html
-
- Posts: 573
- Joined: 25 Apr 2006 15:39
- Location: Cape Town, South Africa