Controlling and monitoring of dryer

From MCS Wiki
(Difference between revisions)
Jump to: navigation, search
 
(9 intermediate revisions by one user not shown)
Line 7: Line 7:
  
  
= Sensors =
+
== Sensors ==
  
 
The SHT15 sensor has capable of measuring temperature and humidity simultaneously. With integrated circuit technology, this sensor is able to measure accurately. While the MLX90614 sensor is using infrared technology to accurately measure temperature from a distance.
 
The SHT15 sensor has capable of measuring temperature and humidity simultaneously. With integrated circuit technology, this sensor is able to measure accurately. While the MLX90614 sensor is using infrared technology to accurately measure temperature from a distance.
  
 
+
&nbsp; <gallery>
 +
File:Cmdryer 01.gif|MLX90614
 +
File:Cmdryer 02.gif|MLX90614
 +
File:Cmdryer 03.gif|MLX90614
 +
File:Cmdryer 04.gif|SHT1x
 +
File:Cmdryer 05.gif|SHT1x
 +
</gallery>
  
&#x5B;&#x5B;File:&#x5D;&#x5D;&#x5B;&#x5B;File:&#x5D;&#x5D;&#x5B;&#x5B;File:&#x5D;&#x5D;
+
== Microcontroller and lcd board ==
  
&#x5B;&#x5B;File:&#x5D;&#x5D;&#x5B;&#x5B;File:&#x5D;&#x5D;
+
&nbsp;The microcontroller used is an ATMega 16-16PU, with a 11059200 Mhz Xtal oscillator. On the schematic are showed inter-connections between micro controller, ISP connector, MLX90614 Sensors, SHT15 sensor and a standard LCD display with 4 lines of 20 characters. As this schematic is also used on some others applications, there is some resistors added on it. This in order to share the programmer pins with the lcd, to have a maximum of microcontroller pins available free. There are some more resistors: they are used to avoid microcontroller output shorts in others uses of this board, and also as connections straps on the pcb. Except that there is nothing of special to said on this “classic” schematic (don’t forget the decoupling capacitors!). It is normally possible to use any other AVR microcontroller and board already available (with the same microcontroller or equivalent), To do that, it will be necessary to change the relevant initialization parameters on the Bascom program. No tests have been done with any other board.&nbsp;
  
&nbsp;
 
  
= Microcontroller and lcd board =
 
  
&nbsp;The microcontroller used is an ATMega 16-16PU, with a 11059200 Mhz Xtal oscillator. On the schematic are showed inter-connections between micro controller, ISP connector, MLX90614 Sensors, SHT15 sensor and a standard LCD display with 4 lines of 20 characters. As this schematic is also used on some others applications, there is some resistors added on it. This in order to share the programmer pins with the lcd, to have a maximum of microcontroller pins available free. There are some more resistors: they are used to avoid microcontroller output shorts in others uses of this board, and also as connections straps on the pcb. Except that there is nothing of special to said on this “classic” schematic (don’t forget the decoupling capacitors!). It is normally possible to use any other AVR microcontroller and board already available (with the same microcontroller or equivalent), To do that, it will be necessary to change the relevant initialization parameters on the Bascom program. No tests have been done with any other board.&nbsp;
+
== Schematic ==
 +
 
 +
[[File:Cmdryer sch.jpg|thumb|center|600px|Schematic]]
 +
 
 +
== BASCOM Code ==
 +
 
 +
<source lang="bascomavr">
 +
$regfile = "m16def.dat" ' specify the used micro
 +
$crystal = 11059200 ' used crystal frequency
 +
$baud = 38400 ' use baud rate
 +
 
 +
'.................................................LCD Configuration....................................................
 +
Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
 +
Config Lcd = 20 * 4
 +
Config Lcdbus = 4
 +
 
 +
 
 +
'.....................................................Variable...........................................................
 +
Dim Interval As Byte , Settemp As Single , Settemptime As Word , Speed As Single , Z As Single
 +
Dim Kbd As Byte , I As Byte , S(5) As String * 3 , B As Single , C As Single , K As Single
 +
Dim Dama As String * 8 , A As Byte , Minute As Byte , Hour As Byte , Fruittemp As Single
 +
Dim Tin As Single , Tout As Single , Rin As Single , Rout As Single , Heatertemp As Single
 +
Dim Adres As Byte , Value As Byte , Temp As Single , Tempword As Word , U As Single
 +
Dim Ctr As Byte , Dataword As Word , Command As Byte , Dis As String * 20 , Calc As Single
 +
Dim Calc2 As Single , Rhlinear As Single , Rhlintemp As Single , Tempc As Single , Tempf As Single
 +
Dim M As Word , Tamp As Single , Pamp As Single , Key As Byte
 +
 
 +
 
 +
'...................................................Sub function...........................................................
 +
 
 +
Declare Sub Read_ram1(byval Adres As Byte , Value As Byte)
 +
Declare Sub Read_ram2(byval Adres As Byte , Value As Byte)
 +
Declare Sub Getit1
 +
Declare Sub Getit2
 +
 
 +
 
 +
 
 +
'...................................................Interrupt........................................................
 +
Enable Interrupts
 +
Config Clock = Soft 'This command inits the clock
 +
Config Date = Ymd , Separator = - ' ANSI-Format
 +
Date$ = "12-02-26"
 +
Time$ = "20:35:00"
 +
Input "Enter the time (hh:mm:ss):" , Time$
 +
Input "Enter the date (mm/dd/yy):" , Date$
 +
 
 +
 
 +
Config Porta.6 = Output ' Lcd intialization
 +
Config Porta.7 = Output ' Heater output
 +
 
 +
 
 +
'....................................................sensor configuration............................................
 +
Config Scl = Portc.0
 +
Config Sda = Portc.1
 +
 
 +
 
 +
 
 +
Const Addressw1 = &B00001000 'slave write address, slave address is 4
 +
Const Addressr1 = &B00001001 'slave read address ,slave address is 4
 +
Const Addressw2 = &B00000110 'slave write address, slave address is 3
 +
Const Addressr2 = &B00000111 'slave read address ,slave address is 3
 +
 
 +
Const C1 = -4
 +
Const C2 = 0.0405
 +
Const C3 = -0.0000028
 +
Const T1c = .01
 +
Const T2 = .00008
 +
Const T1f = .018
 +
 
 +
 
 +
Sck Alias Portc.2
 +
Dataout1 Alias Portc.3
 +
Datain1 Alias Pinc.3
 +
Dataout2 Alias Portc.4
 +
Datain2 Alias Pinc.4
 +
 
 +
Ddrc = &B11111111 'all port C are output
 +
Config Pinc.2 = Output 'sck
 +
Config Pinc.3 = Output
 +
Config Pinc.4 = Output 'datain
 +
 
 +
' .............................................LCD Configuration......................................................
 +
Set Porta.6
 +
Cls
 +
Cursor Off
 +
Wait 1
 +
Cls
 +
 
 +
 
 +
Deflcdchar 0 , 32 , 32 , 32 , 25 , 26 , 4 , 11 , 19 ' Precent
 +
Deflcdchar 1 , 24 , 24 , 32 , 15 , 8 , 8 , 8 , 15 ' Centigerad
 +
 
 +
 
 +
 
 +
 
 +
'reset the serial communications first, it is easily confused!
 +
Set Dataout1
 +
Set Dataout2
 +
For Ctr = 1 To 12
 +
Set Sck
 +
Waitus 2
 +
Reset Sck
 +
Waitus 2
 +
Next Ctr
 +
 
 +
 
 +
Cls
 +
Cursor Off
 +
 
 +
 
 +
'.......................................main program................................................................
 +
Do
 +
'........................................time display..................................................................
 +
Locate 1 , 1
 +
Lcd Time$
 +
Locate 1 , 11
 +
Lcd "20"
 +
Locate 1 , 13
 +
Lcd Date$
 +
'Waitms 250
 +
'...........................................................sensors...................................................
 +
'MLX1
 +
Call Read_ram1(&B00000110 , Value) :
 +
Temp = Tempword * 0.02
 +
Temp = Temp - 273.15
 +
Dama = Fusing(temp , "##.##")
 +
Locate 2 , 1
 +
'Lcd "A=" ; Dama ; Chr(1) 'print T ambiant
 +
 
 +
Call Read_ram1(&B00000111 , Value) :
 +
Temp = Tempword * 0.02
 +
Temp = Temp - 273.15
 +
Heatertemp = Temp
 +
Dama = Fusing(temp , "##.##")
 +
Locate 2 , 11
 +
Lcd "Ht=" ; Dama ; Chr(1) 'again for T object
 +
 
 +
 
 +
'MLX2
 +
Call Read_ram2(&B00000110 , Value) :
 +
Temp = Tempword * 0.02
 +
Temp = Temp - 273.15
 +
Dama = Fusing(temp , "##.##")
 +
Locate 1 , 1
 +
'Lcd "A=" ; Dama ; Chr(1) 'print T ambiant
 +
 
 +
Call Read_ram2(&B00000111 , Value) :
 +
Temp = Tempword * 0.02
 +
Temp = Temp - 273.15
 +
Fruittemp = Temp
 +
Dama = Fusing(temp , "##.##")
 +
Locate 2 , 1
 +
Lcd "Fr=" ; Dama ; Chr(1) 'again for T object
 +
 
 +
 
 +
 
 +
 
 +
 
 +
'SHT1
 +
Command = &B00000011
 +
Call Getit1 'Get the temperature, puts result in "dataword" for us
 +
'
 +
Tempf = T1f * Dataword
 +
Tempf = Tempf - 40
 +
 
 +
Tempc = T1c * Dataword 'get celcius for later calculations and for "the rest of the world"
 +
Tempc = Tempc - 40
 +
Tout = Tempc
 +
Dis = Fusing(tempc , "###.##")
 +
Locate 3 , 11
 +
Lcd "Out=" ; Dis ; Chr(1) ' print T ambiant
 +
 
 +
 
 +
 
 +
'SHT2
 +
 
 +
Command = &B00000011
 +
Call Getit2 'Get the temperature, puts result in "dataword" for us
 +
'
 +
Tempf = T1f * Dataword
 +
Tempf = Tempf - 40
 +
 
 +
Tempc = T1c * Dataword 'get celcius for later calculations and for "the rest of the world"
 +
Tempc = Tempc - 40
 +
Tin = Tempc
 +
Dis = Fusing(tempc , "###.##")
 +
Locate 3 , 1
 +
Lcd "In=" ; Dis ; Chr(1) ' print T ambiant
 +
 
 +
 
 +
 
 +
' SHT1
 +
Command = &B00000101
 +
Call Getit1 'get the humidity
 +
Calc = C2 * Dataword
 +
Calc2 = Dataword * Dataword 'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
 +
Calc2 = C3 * Calc2
 +
Calc = Calc + C1
 +
Rhlinear = Calc + Calc2
 +
 
 +
'Dis = Fusing(rhlinear , "##.##")
 +
'Print "Humidity adjusted for linear = " ; Dis
 +
 
 +
 
 +
Calc = T2 * Dataword
 +
Calc = Calc + T1c
 +
Calc2 = Tempc - 25
 +
Calc = Calc2 * Calc
 +
Rhlintemp = Calc + Rhlinear
 +
Rhlintemp = Tempc / 10.0
 +
Rhlintemp = Rin + Rhlintemp
 +
Dis = Fusing(rhlintemp , "##.##")
 +
Locate 4 , 11
 +
Lcd "Out=" ; Dis ; Chr(0) 'print Humudity
 +
 
 +
'SHT2
 +
Command = &B00000101
 +
Call Getit2 'get the humidity
 +
Calc = C2 * Dataword
 +
Calc2 = Dataword * Dataword 'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
 +
Calc2 = C3 * Calc2
 +
Calc = Calc + C1
 +
Rhlinear = Calc + Calc2
 +
 
 +
'Dis = Fusing(rhlinear , "##.##")
 +
'Print "Humidity adjusted for linear = " ; Dis
 +
 
 +
 
 +
Calc = T2 * Dataword
 +
Calc = Calc + T1c
 +
Calc2 = Tempc - 25
 +
Calc = Calc2 * Calc
 +
Rhlintemp = Calc + Rhlinear
 +
Rin = Rhlintemp
 +
Dis = Fusing(rhlintemp , "##.##")
 +
Locate 4 , 1
 +
Lcd "In=" ; Dis ; Chr(0) 'print Humudity
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
'......................................heater control......................................
 +
M = _hour * 60
 +
M = M + _min
 +
If Settemptime =< M And Settemp >= Heatertemp Then
 +
Set Porta.7
 +
Else
 +
Reset Porta.7
 +
End If
 +
'.....................................sending control....................................
 +
 
 +
 
 +
C = _sec. / Interval
 +
B = Round(c)
 +
 
 +
If B = C Then 'And K = Z
 +
 
 +
If Key <= 5 Then
 +
Pamp = 0.008
 +
Tamp = Key * 0.00015
 +
Tamp = Tamp + 0.035
 +
Elseif Key =< 6 And Key > 5 Then
 +
Pamp = 0.021
 +
Tamp = Key * 0.00015
 +
Tamp = Tamp + 0.035
 +
Elseif Key > 6 And Key < 10 Then
 +
Pamp = Key * 0.01
 +
Tamp = Key * 0.00015
 +
Tamp = Tamp + 0.035
 +
Elseif Key >= 10 And Key < 20 Then
 +
U = Key + 3
 +
Pamp = U * 0.01
 +
Tamp = U * 0.00015
 +
Tamp = Tamp + 0.035
 +
Elseif Key >= 20 Then
 +
U = Key + 6
 +
Pamp = U * 0.01
 +
Tamp = U * 0.00015
 +
Tamp = Tamp + 0.035
 +
End If
 +
 
 +
 
 +
Print Spc(2) ; Time$ ; Spc(3) ; "Ht=" ; Fusing(heatertemp , "#.##") ; Spc(5) ; "Ft=" ; Fusing(fruittemp , "#.##")_
 +
;spc(10) ; "Tin=" ; Fusing(tin , "#.##") ; Spc(10) ; "Tout=" ; Fusing(tout , "#.##")
 +
Print ; Spc(2) ; "RHin=" ; Fusing(rin , "#.##") ; Spc(2) ; "RHout=" ; Fusing(rout , "#.##")_
 +
;Spc(2) ; "Taskamper=" ; Fusing(tamp , "#.###") ; Spc(2) ; "PowerAmper=" ; Fusing(pamp , "#.###")
 +
Print
 +
End If
 +
 
 +
 
 +
Loop
 +
End
 +
 
 +
 
 +
 
 +
 
 +
'...........................................sample of reading a byte from Ram...........................................
 +
 
 +
Sub Read_ram1(byval Adres As Byte , Value As Byte)
 +
 
 +
Tempword = 0
 +
 
 +
I2cstart 'generate start
 +
I2cwbyte Addressw1 'slave adsress(write)
 +
I2cwbyte Adres 'address of EEPROM or commend
 +
 
 +
I2cstart 'repeated start
 +
I2cwbyte Addressr1 'slave address (read)
 +
I2crbyte Value , Ack
 +
Tempword = Value
 +
Shift Tempword , Left , 8
 +
 
 +
I2crbyte Value , Ack
 +
Tempword = Tempword Or Value
 +
 
 +
I2crbyte Value , Nack 'read byte
 +
I2cstop 'generate stop
 +
Rotate Tempword , Left , 8
 +
 
 +
End Sub
 +
 
 +
 
 +
 
 +
 
 +
Sub Read_ram2(byval Adres As Byte , Value As Byte)
 +
 
 +
Tempword = 0
 +
 
 +
I2cstart 'generate start
 +
I2cwbyte Addressw2 'slave adsress(write)
 +
I2cwbyte Adres 'address of EEPROM or commend
 +
 
 +
I2cstart 'repeated start
 +
I2cwbyte Addressr2 'slave address (read)
 +
I2crbyte Value , Ack
 +
Tempword = Value
 +
Shift Tempword , Left , 8
 +
 
 +
I2crbyte Value , Ack
 +
Tempword = Tempword Or Value
 +
 
 +
I2crbyte Value , Nack 'read byte
 +
I2cstop 'generate stop
 +
Rotate Tempword , Left , 8
 +
 
 +
End Sub
 +
 
 +
 
 +
 
 +
Sub Getit1
 +
 
 +
Local Datavalue As Word
 +
Local Databyte As Byte
 +
 
 +
'start with "transmission start"
 +
Set Sck
 +
Reset Dataout1
 +
Reset Sck
 +
Set Sck
 +
Set Dataout1
 +
Reset Sck
 +
 
 +
 
 +
'now send the command
 +
Shiftout Dataout1 , Sck , Command , 1
 +
 
 +
Ddrc = &B11110111 'datain is now input
 +
Config Pinc.3 = Input 'datain
 +
Set Sck 'click one more off
 +
Reset Sck
 +
Waitus 10 'no idea why, but it doesn't work without it!
 +
Bitwait Pinc.3 , Reset 'wait for the chip to have data ready
 +
 
 +
Shiftin Datain1 , Sck , Databyte , 1 'get the MSB
 +
Datavalue = Databyte
 +
 
 +
Ddrc = &B11111111
 +
Config Pinc.3 = Output
 +
 
 +
Reset Dataout1 'this is the tricky part- Lot's of hair pulling- have to tick the ack!
 +
Set Sck
 +
Reset Sck
 +
 
 +
Ddrc = &B11110111 'datain is now input
 +
Config Pinc.3 = Input
 +
 
 +
Shiftin Datain1 , Sck , Databyte , 1 'get the LSB
 +
Shift Datavalue , Left , 8
 +
Datavalue = Datavalue Or Databyte
 +
'don't tick the clock or ack since we don't need the CRC value, leave it hanging!
 +
Dataword = Datavalue
 +
 
 +
Ddrc = &B11111111
 +
Config Pinc.3 = Output
 +
 
 +
Reset Dataout1
 +
Set Sck
 +
Reset Sck
 +
 
 +
Ddrc = &B11110111 'datain is now input
 +
Config Pinc.3 = Input
 +
 
 +
Shiftin Datain1 , Sck , Databyte , 1 'not using the CRC value for now- can't figure it out! Anybody know how to impliment?
 +
'Print "CRC value was - " ; Databyte
 +
 
 +
Ddrc = &B11111111
 +
Config Pinc.3 = Output
 +
 
 +
Set Dataout1
 +
Set Sck
 +
Reset Sck
 +
End Sub
 +
 
 +
 
 +
 
 +
Sub Getit2
 +
 
 +
Local Datavalue As Word
 +
Local Databyte As Byte
 +
 
 +
'start with "transmission start"
 +
Set Sck
 +
Reset Dataout2
 +
Reset Sck
 +
Set Sck
 +
Set Dataout2
 +
Reset Sck
 +
 
 +
 
 +
'now send the command
 +
Shiftout Dataout2 , Sck , Command , 1
 +
 
 +
Ddrc = &B11101111 'datain is now input
 +
Config Pinc.4 = Input 'datain
 +
Set Sck 'click one more off
 +
Reset Sck
 +
Waitus 10 'no idea why, but it doesn't work without it!
 +
Bitwait Pinc.4 , Reset 'wait for the chip to have data ready
 +
 
 +
Shiftin Datain2 , Sck , Databyte , 1 'get the MSB
 +
Datavalue = Databyte
 +
 
 +
Ddrc = &B11111111
 +
Config Pinc.4 = Output
 +
 
 +
Reset Dataout2 'this is the tricky part- Lot's of hair pulling- have to tick the ack!
 +
Set Sck
 +
Reset Sck
 +
 
 +
Ddrc = &B11101111 'datain is now input
 +
Config Pinc.4 = Input
 +
 
 +
Shiftin Datain2 , Sck , Databyte , 1 'get the LSB
 +
Shift Datavalue , Left , 8
 +
Datavalue = Datavalue Or Databyte
 +
'don't tick the clock or ack since we don't need the CRC value, leave it hanging!
 +
Dataword = Datavalue
 +
 
 +
Ddrc = &B11111111
 +
Config Pinc.4 = Output
 +
 
 +
Reset Dataout2
 +
Set Sck
 +
Reset Sck
 +
 
 +
Ddrc = &B11101111 'datain is now input
 +
Config Pinc.4 = Input
 +
 
 +
Shiftin Datain2 , Sck , Databyte , 1 'not using the CRC value for now- can't figure it out! Anybody know how to impliment?
 +
'Print "CRC value was - " ; Databyte
 +
 
 +
Ddrc = &B11111111
 +
Config Pinc.4 = Output
 +
 
 +
Set Dataout2
 +
Set Sck
 +
Reset Sck
 +
End Sub
 +
</source>
 +
 
 +
 
 +
 
 +
== Author ==
 +
 
 +
'''Written by:''' Mohammad Jafar Dalvand , Iran, University of Tehran
 +
 
 +
'''Email Address:''' Dalvand@ut.ac.ir
 +
 
 +
 
 +
 
 +
[[Category:Projects]]

Latest revision as of 11:39, 17 February 2013

Contents

Description

Here is little project, which in the next once proves the superiority a controller AVR on rest processor.

This project was designed to control and monitoring the environmental conditions of a dryer that includes a set of sensors for measuring temperature and humidity. Two types of temperature sensors are used, SHT15 for ambient temperature measurement and MLX90614 to measure the surface temperature of the heater and the food.


Sensors

The SHT15 sensor has capable of measuring temperature and humidity simultaneously. With integrated circuit technology, this sensor is able to measure accurately. While the MLX90614 sensor is using infrared technology to accurately measure temperature from a distance.

 

Microcontroller and lcd board

 The microcontroller used is an ATMega 16-16PU, with a 11059200 Mhz Xtal oscillator. On the schematic are showed inter-connections between micro controller, ISP connector, MLX90614 Sensors, SHT15 sensor and a standard LCD display with 4 lines of 20 characters. As this schematic is also used on some others applications, there is some resistors added on it. This in order to share the programmer pins with the lcd, to have a maximum of microcontroller pins available free. There are some more resistors: they are used to avoid microcontroller output shorts in others uses of this board, and also as connections straps on the pcb. Except that there is nothing of special to said on this “classic” schematic (don’t forget the decoupling capacitors!). It is normally possible to use any other AVR microcontroller and board already available (with the same microcontroller or equivalent), To do that, it will be necessary to change the relevant initialization parameters on the Bascom program. No tests have been done with any other board. 


Schematic

Schematic

BASCOM Code

$regfile = "m16def.dat" ' specify the used micro
$crystal = 11059200 ' used crystal frequency
$baud = 38400 ' use baud rate
 
'.................................................LCD Configuration....................................................
Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
Config Lcd = 20 * 4
Config Lcdbus = 4
 
 
'.....................................................Variable...........................................................
Dim Interval As Byte , Settemp As Single , Settemptime As Word , Speed As Single , Z As Single
Dim Kbd As Byte , I As Byte , S(5) As String * 3 , B As Single , C As Single , K As Single
Dim Dama As String * 8 , A As Byte , Minute As Byte , Hour As Byte , Fruittemp As Single
Dim Tin As Single , Tout As Single , Rin As Single , Rout As Single , Heatertemp As Single
Dim Adres As Byte , Value As Byte , Temp As Single , Tempword As Word , U As Single
Dim Ctr As Byte , Dataword As Word , Command As Byte , Dis As String * 20 , Calc As Single
Dim Calc2 As Single , Rhlinear As Single , Rhlintemp As Single , Tempc As Single , Tempf As Single
Dim M As Word , Tamp As Single , Pamp As Single , Key As Byte
 
 
'...................................................Sub function...........................................................
 
Declare Sub Read_ram1(byval Adres As Byte , Value As Byte)
Declare Sub Read_ram2(byval Adres As Byte , Value As Byte)
Declare Sub Getit1
Declare Sub Getit2
 
 
 
'...................................................Interrupt........................................................
Enable Interrupts
Config Clock = Soft 'This command inits the clock
Config Date = Ymd , Separator = - ' ANSI-Format
Date$ = "12-02-26"
Time$ = "20:35:00"
Input "Enter the time (hh:mm:ss):" , Time$
Input "Enter the date (mm/dd/yy):" , Date$
 
 
Config Porta.6 = Output ' Lcd intialization
Config Porta.7 = Output ' Heater output
 
 
'....................................................sensor configuration............................................
Config Scl = Portc.0
Config Sda = Portc.1
 
 
 
Const Addressw1 = &B00001000 'slave write address, slave address is 4
Const Addressr1 = &B00001001 'slave read address ,slave address is 4
Const Addressw2 = &B00000110 'slave write address, slave address is 3
Const Addressr2 = &B00000111 'slave read address ,slave address is 3
 
Const C1 = -4
Const C2 = 0.0405
Const C3 = -0.0000028
Const T1c = .01
Const T2 = .00008
Const T1f = .018
 
 
Sck Alias Portc.2
Dataout1 Alias Portc.3
Datain1 Alias Pinc.3
Dataout2 Alias Portc.4
Datain2 Alias Pinc.4
 
Ddrc = &B11111111 'all port C are output
Config Pinc.2 = Output 'sck
Config Pinc.3 = Output
Config Pinc.4 = Output 'datain
 
' .............................................LCD Configuration......................................................
Set Porta.6
Cls
Cursor Off
Wait 1
Cls
 
 
Deflcdchar 0 , 32 , 32 , 32 , 25 , 26 , 4 , 11 , 19 ' Precent
Deflcdchar 1 , 24 , 24 , 32 , 15 , 8 , 8 , 8 , 15 ' Centigerad
 
 
 
 
'reset the serial communications first, it is easily confused!
Set Dataout1
Set Dataout2
For Ctr = 1 To 12
 Set Sck
 Waitus 2
 Reset Sck
 Waitus 2
Next Ctr
 
 
Cls
Cursor Off
 
 
'.......................................main program................................................................
Do
'........................................time display..................................................................
Locate 1 , 1
 Lcd Time$
Locate 1 , 11
 Lcd "20"
Locate 1 , 13
 Lcd Date$
 'Waitms 250
'...........................................................sensors...................................................
 'MLX1
 Call Read_ram1(&B00000110 , Value) :
 Temp = Tempword * 0.02
 Temp = Temp - 273.15
 Dama = Fusing(temp , "##.##")
 Locate 2 , 1
 'Lcd "A=" ; Dama ; Chr(1) 'print T ambiant
 
 Call Read_ram1(&B00000111 , Value) :
 Temp = Tempword * 0.02
 Temp = Temp - 273.15
 Heatertemp = Temp
 Dama = Fusing(temp , "##.##")
 Locate 2 , 11
 Lcd "Ht=" ; Dama ; Chr(1) 'again for T object
 
 
 'MLX2
 Call Read_ram2(&B00000110 , Value) :
 Temp = Tempword * 0.02
 Temp = Temp - 273.15
 Dama = Fusing(temp , "##.##")
 Locate 1 , 1
 'Lcd "A=" ; Dama ; Chr(1) 'print T ambiant
 
 Call Read_ram2(&B00000111 , Value) :
 Temp = Tempword * 0.02
 Temp = Temp - 273.15
 Fruittemp = Temp
 Dama = Fusing(temp , "##.##")
 Locate 2 , 1
 Lcd "Fr=" ; Dama ; Chr(1) 'again for T object
 
 
 
 
 
 'SHT1
 Command = &B00000011
 Call Getit1 'Get the temperature, puts result in "dataword" for us
 '
 Tempf = T1f * Dataword
 Tempf = Tempf - 40
 
 Tempc = T1c * Dataword 'get celcius for later calculations and for "the rest of the world"
 Tempc = Tempc - 40
 Tout = Tempc
 Dis = Fusing(tempc , "###.##")
 Locate 3 , 11
 Lcd "Out=" ; Dis ; Chr(1) ' print T ambiant
 
 
 
 'SHT2
 
 Command = &B00000011
 Call Getit2 'Get the temperature, puts result in "dataword" for us
 '
 Tempf = T1f * Dataword
 Tempf = Tempf - 40
 
 Tempc = T1c * Dataword 'get celcius for later calculations and for "the rest of the world"
 Tempc = Tempc - 40
 Tin = Tempc
 Dis = Fusing(tempc , "###.##")
 Locate 3 , 1
 Lcd "In=" ; Dis ; Chr(1) ' print T ambiant
 
 
 
 ' SHT1
 Command = &B00000101
 Call Getit1 'get the humidity
 Calc = C2 * Dataword
 Calc2 = Dataword * Dataword 'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
 Calc2 = C3 * Calc2
 Calc = Calc + C1
 Rhlinear = Calc + Calc2
 
 'Dis = Fusing(rhlinear , "##.##")
 'Print "Humidity adjusted for linear = " ; Dis
 
 
 Calc = T2 * Dataword
 Calc = Calc + T1c
 Calc2 = Tempc - 25
 Calc = Calc2 * Calc
 Rhlintemp = Calc + Rhlinear
 Rhlintemp = Tempc / 10.0
 Rhlintemp = Rin + Rhlintemp
 Dis = Fusing(rhlintemp , "##.##")
 Locate 4 , 11
 Lcd "Out=" ; Dis ; Chr(0) 'print Humudity
 
 'SHT2
 Command = &B00000101
 Call Getit2 'get the humidity
 Calc = C2 * Dataword
 Calc2 = Dataword * Dataword 'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
 Calc2 = C3 * Calc2
 Calc = Calc + C1
 Rhlinear = Calc + Calc2
 
 'Dis = Fusing(rhlinear , "##.##")
 'Print "Humidity adjusted for linear = " ; Dis
 
 
 Calc = T2 * Dataword
 Calc = Calc + T1c
 Calc2 = Tempc - 25
 Calc = Calc2 * Calc
 Rhlintemp = Calc + Rhlinear
 Rin = Rhlintemp
 Dis = Fusing(rhlintemp , "##.##")
 Locate 4 , 1
 Lcd "In=" ; Dis ; Chr(0) 'print Humudity
 
 
 
 
 
 
 
 
'......................................heater control......................................
M = _hour * 60
M = M + _min
If Settemptime =< M And Settemp >= Heatertemp Then
 Set Porta.7
 Else
 Reset Porta.7
 End If
 '.....................................sending control....................................
 
 
C = _sec. / Interval
B = Round(c)
 
If B = C Then 'And K = Z
 
If Key <= 5 Then
Pamp = 0.008
Tamp = Key * 0.00015
Tamp = Tamp + 0.035
Elseif Key =< 6 And Key > 5 Then
Pamp = 0.021
Tamp = Key * 0.00015
Tamp = Tamp + 0.035
Elseif Key > 6 And Key < 10 Then
Pamp = Key * 0.01
Tamp = Key * 0.00015
Tamp = Tamp + 0.035
Elseif Key >= 10 And Key < 20 Then
U = Key + 3
Pamp = U * 0.01
Tamp = U * 0.00015
Tamp = Tamp + 0.035
Elseif Key >= 20 Then
U = Key + 6
Pamp = U * 0.01
Tamp = U * 0.00015
Tamp = Tamp + 0.035
End If
 
 
 Print Spc(2) ; Time$ ; Spc(3) ; "Ht=" ; Fusing(heatertemp , "#.##") ; Spc(5) ; "Ft=" ; Fusing(fruittemp , "#.##")_
 ;spc(10) ; "Tin=" ; Fusing(tin , "#.##") ; Spc(10) ; "Tout=" ; Fusing(tout , "#.##")
 Print ; Spc(2) ; "RHin=" ; Fusing(rin , "#.##") ; Spc(2) ; "RHout=" ; Fusing(rout , "#.##")_
 ;Spc(2) ; "Taskamper=" ; Fusing(tamp , "#.###") ; Spc(2) ; "PowerAmper=" ; Fusing(pamp , "#.###")
 Print
End If
 
 
Loop
End
 
 
 
 
'...........................................sample of reading a byte from Ram...........................................
 
Sub Read_ram1(byval Adres As Byte , Value As Byte)
 
 Tempword = 0
 
 I2cstart 'generate start
 I2cwbyte Addressw1 'slave adsress(write)
 I2cwbyte Adres 'address of EEPROM or commend
 
 I2cstart 'repeated start
 I2cwbyte Addressr1 'slave address (read)
 I2crbyte Value , Ack
 Tempword = Value
 Shift Tempword , Left , 8
 
 I2crbyte Value , Ack
 Tempword = Tempword Or Value
 
 I2crbyte Value , Nack 'read byte
 I2cstop 'generate stop
Rotate Tempword , Left , 8
 
End Sub
 
 
 
 
Sub Read_ram2(byval Adres As Byte , Value As Byte)
 
 Tempword = 0
 
 I2cstart 'generate start
 I2cwbyte Addressw2 'slave adsress(write)
 I2cwbyte Adres 'address of EEPROM or commend
 
 I2cstart 'repeated start
 I2cwbyte Addressr2 'slave address (read)
 I2crbyte Value , Ack
 Tempword = Value
 Shift Tempword , Left , 8
 
 I2crbyte Value , Ack
 Tempword = Tempword Or Value
 
 I2crbyte Value , Nack 'read byte
 I2cstop 'generate stop
Rotate Tempword , Left , 8
 
End Sub
 
 
 
Sub Getit1
 
 Local Datavalue As Word
 Local Databyte As Byte
 
 'start with "transmission start"
 Set Sck
 Reset Dataout1
 Reset Sck
 Set Sck
 Set Dataout1
 Reset Sck
 
 
 'now send the command
 Shiftout Dataout1 , Sck , Command , 1
 
 Ddrc = &B11110111 'datain is now input
 Config Pinc.3 = Input 'datain
 Set Sck 'click one more off
 Reset Sck
 Waitus 10 'no idea why, but it doesn't work without it!
 Bitwait Pinc.3 , Reset 'wait for the chip to have data ready
 
 Shiftin Datain1 , Sck , Databyte , 1 'get the MSB
 Datavalue = Databyte
 
 Ddrc = &B11111111
 Config Pinc.3 = Output
 
 Reset Dataout1 'this is the tricky part- Lot's of hair pulling- have to tick the ack!
 Set Sck
 Reset Sck
 
 Ddrc = &B11110111 'datain is now input
 Config Pinc.3 = Input
 
 Shiftin Datain1 , Sck , Databyte , 1 'get the LSB
 Shift Datavalue , Left , 8
 Datavalue = Datavalue Or Databyte
 'don't tick the clock or ack since we don't need the CRC value, leave it hanging!
 Dataword = Datavalue
 
 Ddrc = &B11111111
 Config Pinc.3 = Output
 
 Reset Dataout1
 Set Sck
 Reset Sck
 
 Ddrc = &B11110111 'datain is now input
 Config Pinc.3 = Input
 
 Shiftin Datain1 , Sck , Databyte , 1 'not using the CRC value for now- can't figure it out! Anybody know how to impliment?
 'Print "CRC value was - " ; Databyte
 
 Ddrc = &B11111111
 Config Pinc.3 = Output
 
 Set Dataout1
 Set Sck
 Reset Sck
End Sub
 
 
 
Sub Getit2
 
 Local Datavalue As Word
 Local Databyte As Byte
 
 'start with "transmission start"
 Set Sck
 Reset Dataout2
 Reset Sck
 Set Sck
 Set Dataout2
 Reset Sck
 
 
 'now send the command
 Shiftout Dataout2 , Sck , Command , 1
 
 Ddrc = &B11101111 'datain is now input
 Config Pinc.4 = Input 'datain
 Set Sck 'click one more off
 Reset Sck
 Waitus 10 'no idea why, but it doesn't work without it!
 Bitwait Pinc.4 , Reset 'wait for the chip to have data ready
 
 Shiftin Datain2 , Sck , Databyte , 1 'get the MSB
 Datavalue = Databyte
 
 Ddrc = &B11111111
 Config Pinc.4 = Output
 
 Reset Dataout2 'this is the tricky part- Lot's of hair pulling- have to tick the ack!
 Set Sck
 Reset Sck
 
 Ddrc = &B11101111 'datain is now input
 Config Pinc.4 = Input
 
 Shiftin Datain2 , Sck , Databyte , 1 'get the LSB
 Shift Datavalue , Left , 8
 Datavalue = Datavalue Or Databyte
 'don't tick the clock or ack since we don't need the CRC value, leave it hanging!
 Dataword = Datavalue
 
 Ddrc = &B11111111
 Config Pinc.4 = Output
 
 Reset Dataout2
 Set Sck
 Reset Sck
 
 Ddrc = &B11101111 'datain is now input
 Config Pinc.4 = Input
 
 Shiftin Datain2 , Sck , Databyte , 1 'not using the CRC value for now- can't figure it out! Anybody know how to impliment?
 'Print "CRC value was - " ; Databyte
 
 Ddrc = &B11111111
 Config Pinc.4 = Output
 
 Set Dataout2
 Set Sck
 Reset Sck
End Sub


Author

Written by: Mohammad Jafar Dalvand , Iran, University of Tehran

Email Address: Dalvand@ut.ac.ir

Personal tools
Namespaces
Variants
Actions
Navigation
Language