2nd place in 2011 competition bascom.at.ua
Much were written about
this amazing " cubes ", has here is solved too to use given
miraculously. Idea was such, support micro-climate in cellar.
For conclusion of information
is used MELT 2х line 16 class, keys of
management with old motherboard 15N03H on 30 volts and ATMEGA 8 -
16PU.
Long hung around with code, on indicator were
removed numerals, well even close not reminded true importance. What turned out
to be, reasons 2, converter with 5 on 3,3 volts and recalculation itself got
data.
With first dared simply,
there is worker of the decision from DECODER’а http://we.easyelectronics.ru/part/datchik-temperatury-i-vlazhnosti-sht21.html
: 
With code it happened to
to ask the help beside community, trivial errors from ignorance Bascom's, all we teach!
That was got.


The First cut-in, call
at in menu and choose the button upwards, downwards adjustment hours or limits
of the functioning(working) the ventilator and heating. After striking IN-
entering, all installed parameters are saved in memories MC. This 8 first cells
to memories.
At achievement upper придела to moisture is included ventilator, but at reduction
of the temperature - a heating.
The Ventilators use from
BP computer, heater this Car heater sittings of the car.
CHtob was a best return of the heat, glue her(it) on metallic the base 300*300
mm. If occurs change the ambiance, data and time, are sent on computer through
RS-485.
The Disappearings of the
feeding, in the same way оповещается through port RS-485.
(if adapt autonomous feeding from telephone or simply battery on 4,5 volts.)
Eats the block from 20 volts.
Certainly this not
masterpiece, but works as it is necessary.
Source code:
'*******************************************************************************
'* Description : SHT21_POD *
'* Revision : 1.0 *
'* Controller : ATMEGA8 *
'* Compiler : BASCOM-AVR 1.11.9.8 DEMO *
'* Author : 'AV_ , 2011 *
'* Web : HTTP://WWW *
'*******************************************************************************
'
'************************** Tip_mikrokontrollera *******************************
$regfile = "m8def.dat" 'For POD mega8
$crystal = 4000000 'quartz 4 ĚĺĂÖ
$baud = 19200
'$lib "lcd4.lbx" 'use 4-áčňíîĺ connection display by means of alternative library
$lib "mcsbyte.lbx"
$lib "ds1307clock.lib" 'we connect library ds1307
$lib "modbus.lbx" 'we connect library modbus
$hwstack = 40
$swstack = 16
$framesize = 32
$eeprom
'$sim
'*********************** deskside port ***********************************
Config Lcd = 16 * 2 ' screen 16*2 (any with controller HD44780)
Config Lcdpin = Pin , Rs = Portb.0 , E = Portb.1 , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5
Config Scl = Portc.5 'we connect i2c SCL
Config Sda = Portc.4 'we connect i2c SDA
Const Ds1307w = &HD0 'Constants for functioning ń ds1307 W
Const Ds1307r = &HD1 'Constants for functioning ń ds1307 R
Config Portc.3 = Input 'leg "feeding"
Config Portc.0 = Output 'leg where is connected breaker Q1
Config Portc.2 = Output 'leg where is connected breaker Q2
Config Portd.2 = Output 'leg for switching RS485 issue acceptance
Config Print = Portd.2 , Mode = Reset 'ďî đĺńĺňó
Config Serialin = Buffered , Size = 250 'Buffer RS485 where all
Cursor Off 'We Switch off cursor
Cls 'Clearing the screen
'*** we shall adjust port for connection of the buttons and others device (Q1,Q2,Hair dryer heating)
Set Portd.7 : Ok Alias Pind.7 'Ustanovka"set" internal resistor on + entering
Set Portd.6 : Esc Alias Pind.6 'Ustanovka"set" internal resistor on + menu
Set Portd.4 : Up Alias Pind.4 'Ustanovka"set" internal resistor on + âĺđő
Set Portd.5 : Down Alias Pind.5 'Ustanovka"set" internal resistor on + íčç
Set Portd.3 : Fen Alias Pind.3 'Ustanovka"set" internal resistor on + ôĺí
Ďčňŕíčĺ Alias Pinc.3 'Feeding no!
Q1 Alias Portc.0 'adjusting the connection Q1
Q2 Alias Portc.2 'adjusting the connection Q2
Q1 = 0
Q2 = 0
'*********************** Variable SHT-21 *************************************
Dim Data1 As Byte
Dim Data2 As Byte
Dim Crc As Byte
Dim Datat As Word
Dim Datah As Word
Dim T As Single
Dim H As Single
Dim T0 As Single 'Keep for comparison
Dim H0 As Single 'Keep for comparison
'***
Dim X1 As Byte 'Declare byte variable X1(the temporary data)
Dim Ay As Byte 'Declare byte variable Ay(cycle)
Dim J1 As Byte 'Declare byte variable J1(year)
Dim M1 As Byte 'Declare byte variable M1(month)
Dim D1 As Byte 'Declare byte variable D1(äĺíü)
Dim H1 As Byte 'Declare byte variable H1(÷ŕń)
Dim Min1 As Byte 'Declare byte variable Min1(ěčíóňŕ)
'************************* Mounting ****************************************
Dim A As Integer 'Declare safe variable A
Dim B As Integer 'Declare safe variable B
Dim Tem1 As Single 'Declare safe variable Tem1
Dim Tem2 As Single 'Declare safe variable Tem2
Dim C As Integer 'Declare safe variable C
Dim D As Integer 'Declare safe variable D
Dim Vla1 As Single 'Declare safe variable Vla1
Dim Vla2 As Single 'Declare safe variable Vla2
'***************** Variable Eeprom ********************************
Dim Ae As Eram Integer 'Declare safe variable in EEPROM Ae
Dim Be As Eram Integer 'Declare safe variable in EEPROM Be
Dim Ce As Eram Integer 'Declare safe variable in EEPROM Ce
Dim De As Eram Integer 'Declare safe variable in EEPROM De
A = Ae
B = Be
C = Ce
D = De
'*** Variable hours ***
Dim Seco As Byte
Dim Mine As Byte
Dim Hour As Byte
Dim Day As Byte
Dim Dat As Byte
Dim Month As Byte
Dim Year As Byte
'***
'************************************Procedures**********************************
Declare Sub Sht21th 'Declare procedure Termodatchika
Declare Sub Ââĺđő_âíčç() 'Declare procedure Upwards downwards
Declare Sub Ôĺí 'Declare procedure HAIR DRYER
Declare Sub Íŕăđĺâ 'Declare procedure a Heating
'***
Deflcdchar 0 , 8 , 20 , 8 , 3 , 4 , 4 , 4 , 3 ' Sign to degree
Deflcdchar 1 , 32 , 4 , 4 , 14 , 14 , 31 , 31 , 14 ' Sign to moisture
Deflcdchar 2 , 4 , 10 , 17 , 31 , 17 , 17 , 17 , 31 ' Sign of the cellar
Deflcdchar 3 , 32 , 4 , 4 , 14 , 14 , 31 , 31 , 32 ' Sign top
Deflcdchar 4 , 32 , 31 , 31 , 14 , 14 , 4 , 4 , 32 ' Sign bottom
'address of the microcircuit-sensor SHT21 H80- record, H81- reading 'Commands for governing SHT21 whole 7:
'0xE3 - Measure the temperature. Herewith for time of the measurement line SCL will is pressed to the land.
'0xE5 - Measure moisture. The Line SCL so- snuggles to the land for time of the measurement.
'0xF3 - Measure the temperature. This time sensor does not press the line SCL for time çŕěĺđŕ.
'0xF5 - Measure moisture. The Line SCL does not snuggle.
'0xE6 - Write given in user register.
'0xE7 - Read given from user register.
'0xFE - Reboot the sensor.
'******** Procedures *********
Íŕ÷ŕëî:
Cls
Lcd "*** SHT-21 *** "
Do
Gosub Clock 'shall hear time
Gosub Sht21th 'shall hear temperature and moisture
Waitms 900 'hold up
Gosub Xx
Call Íŕăđĺâ 'Cause subroutine(procedure) "Heating"
Call Ôĺí 'Cause subroutine(procedure) "Hair dryer"
Cls 'remove time and all rest
Lcd Chr(2) ; Fusing(t , "#.#") ; Chr(0) ; " " ; Chr(1) ; Fusing(h , "#.#") ; "%"
Locate 2 , 1
Lcd " " ; Hour ; ":" ; Mine ; " " ; Dat ; "/" ; Month ; "/" ; Day
If Esc = 0 Then Goto Meni 'buttons menu
Loop
End
'*** SHT-21T temperature ***
Sub Sht21th:
I2cstart
I2cwbyte &H80 'address of the microcircuit-sensor SHT21
I2cwbyte &HE3 'choice of the measurement of the temperature in normal mode
Waitms 100 'measurement
I2cstart
I2cwbyte &H81 'reading the result of the measurement
I2crbyte Data1 , Ack 'receiving the senior byte, wait ńëóäóţůčé byte
I2crbyte Data2 , Ack 'receiving the younger byte
I2crbyte Crc , Nack 'receiving the byte of the control total (possible on it downtrodden)
I2cstop 'end of the contact
'***We Consider***
Datat = Data1
Shift Datat , Left , 8 'shift on 8 bits
Datat = Datat + Data2
T = Datat * 175.72
T = T / 65536
T = T - 46.85
'***All***
'*** SHT-21H moisture ***
'Sht21h:
I2cstart
I2cwbyte &H80 'ŕäđĺń ěčęđîńőĺěű-äŕň÷čęŕ SHT21
I2cwbyte &HE5 'choice of the measurement to moisture in normal mode
Waitms 100 'čçěĺđĺíčĺ
I2cstart
I2cwbyte &H81 '÷ňĺíčĺ đĺçóëüňŕňŕ čçěĺđĺíč˙
I2crbyte Data1 , Ack 'ďđčĺě ńňŕđřĺăî áŕéňŕ, ćäĺě ńëóäóţůčé áŕéň
I2crbyte Data2 , Ack 'ďđčĺě ěëŕäřĺăî áŕéňŕ
I2crbyte Crc , Nack 'ďđčĺě áŕéňŕ ęîíňđîëüíîé ńóěěű (ěîćíî íŕ íĺăî çŕáčňü)
I2cstop 'ęîíĺö îáůĺíč˙
'***Count***
Datah = Data1
Shift Datah , Left , 8 'shift on 8 bits
Datah = Datah + Data2
H = Datah * 125
H = H / 65536
H = H - 6
'***All***
End Sub
'*** We Compare data ***
Xx:
If T <> T0 Then
T0 = T : Print Fusing(t , "#.#") ; "C " ; Hour ; ":" ; Mine ; " " ; Dat ; "/" ; Month ; "/" ; Dat
If H <> H0 Then
H0 = H : Print Fusing(h , "#.#") ; "% " ; Hour ; ":" ; Mine ; " " ; Dat ; "/" ; Month ; "/" ; Dat
If Ďčňŕíčĺ < 1 Then
Print "*ÍĹŇ ĎČŇŔÍČß* NO voltages " ; Hour ; ":" ; Mine ; " " ; Dat ; "/" ; Month ; "/" ; Dat
End If
End If
End If
Return
'*** we define current time
Clock: 'standard work with RTC ds1307 on extraction data
I2cstart
I2cwbyte Ds1307w
I2cwbyte &H00
I2cstart
I2cwbyte Ds1307r
I2crbyte Seco , Ack
I2crbyte Mine , Ack
I2crbyte Hour , Ack
I2crbyte Day , Ack
I2crbyte Dat , Ack
I2crbyte Month , Ack
I2crbyte Year , Nack
I2cstop
Seco = Makedec(seco) : Mine = Makedec(mine) : Hour = Makedec(hour)
Day = Makedec(day) : Dat = Makedec(dat) : Month = Makedec(month) : Year = Makedec(year)
Return
'*** Menu
Meni:
Cls
Rem Ust. time
Lcd "©cż. łpeĽe˝¸ " ; Chr(3)
Locate 2 , 1
Rem Ust. sensor
Lcd "©cż. ăażŔ¸şa " ; Chr(4)
Do
If Up = 0 Then Goto Ust_v
If Down = 0 Then Goto Ust_d
If Ok = 0 Then Goto Íŕ÷ŕëî
Loop
'***
Ust_v:
'*******************************************************************************
'Choice and following conservation in memory ds1307, year
Cls
Ay = 0
X1 = Year
Do
If X1 > 99 Then X1 = 9
If X1 < 9 Then X1 = 99
Locate 1 , 1
Lcd "*>ŕaża<*"
Locate 2 , 1
Lcd "ˇoă: " ; X1 ; " "
Ââĺđő_âíčç
J1 = X1
Loop Until Ay = 1
'*******************************************************************************
'Choice and following conservation in memory ds1307, month
Cls
Ay = 0
X1 = Month
Do
If X1 > 12 Then X1 = 1
If X1 < 1 Then X1 = 12
Locate 1 , 1
Lcd "*>ŕaża<*"
Locate 2 , 1
Lcd "MecÇĺ: " ; X1 ; " "
Ââĺđő_âíčç
M1 = X1
Loop Until Ay = 1
'*******************************************************************************
'Choice and following conservation in memory ds1307, day
Cls
Ay = 0
X1 = Day
Do
If X1 > 31 Then X1 = 1
If X1 < 1 Then X1 = 31
Locate 1 , 1
Lcd "*>ŕaża<*"
Locate 2 , 1
Lcd "ŕe˝Ä: " ; X1 ; " "
Ââĺđő_âíčç
D1 = X1
Loop Until Ay = 1
Year = J1
Month = M1
Day = D1
Gosub Íŕńňđîéęŕ_äŕňű
'*******************************************************************************
'Choice and following conservation in memory ds1307, hour
Cls
Ay = 0
X1 = Hour
Do
If X1 > 23 Then X1 = 0
If X1 < 0 Then X1 = 23
Locate 1 , 1
Lcd "*>BpeĽÇ<*"
Locate 2 , 1
Lcd "«acĂ: " ; X1 ; " "
Ââĺđő_âíčç
H1 = X1
Loop Until Ay = 1
'*******************************************************************************
'Choice and following conservation in memory ds1307, minutes
Cls
Ay = 0
X1 = Mine
Do
If X1 > 59 Then X1 = 0
If X1 < 1 Then X1 = 59
Locate 1 , 1
Lcd "*>BpeĽÇ<*"
Locate 2 , 1
Lcd "M¸˝yżĂ: " ; X1 ; " "
Ââĺđő_âíčç
Min1 = X1
Loop Until Ay = 1
Hour = H1
Mine = Min1
Seco = 0
Gosub Íŕńňđîéęŕ_âđĺěĺíč
Goto Íŕ÷ŕëî
'***
Íŕńňđîéęŕ_äŕňű:
Day = Makebcd(day) : Month = Makebcd(month) : Year = Makebcd(year)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 4 ' starting address in 1307
I2cwbyte Day ' Send Day
I2cwbyte Month ' Mon
I2cwbyte Year ' ăîä
I2cstop
Return
Íŕńňđîéęŕ_âđĺěĺíč:
Seco = Makebcd(seco) : Mine = Makebcd(mine) : Hour = Makebcd(hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte Seco ' Send Data to SECONDS
I2cwbyte Mine ' min
I2cwbyte Hour ' Hours
I2cstop
Return
'*******************************************************************************
Ust_d:
'***
'Installation and conservation in eeprom mc, shutdown Q2
Cls
Ay = 0
X1 = A
Do
If X1 > 10 Then X1 = 7
If X1 < 7 Then X1 = 10
Locate 1 , 1
Lcd "[ Bòop żeĽľ. ]"
Locate 2 , 1
Lcd "TeĽľ. łş».: " ; X1 ; " "
Ââĺđő_âíčç
Tem1 = X1
Loop Until Ay = 1
A = Tem1
'*******************************************************************************
'Installation and conservation in eeprom mc, cut-in Q2
Cls
Ay = 0
X1 = B
Do
If X1 > 10 Then X1 = 4
If X1 < 4 Then X1 = 10
Locate 1 , 1
Lcd "[ Bòop żeĽľ. ]"
Locate 2 , 1
Lcd "TeĽľ. łĂş».: " ; X1 ; " "
Ââĺđő_âíčç
Tem2 = X1
Loop Until Ay = 1
B = Tem2
'***
'Installation and conservation in eeprom mc, cut-in Q1
Cls
Ay = 0
X1 = C
Do
If X1 > 80 Then X1 = 50
If X1 < 50 Then X1 = 80
Locate 1 , 1
Lcd "[ ©cż.ł»a¶˝ocż¸]"
Locate 2 , 1
Lcd "B»a¶. łş».: " ; X1 ; " "
Ââĺđő_âíčç
Vla1 = X1
Loop Until Ay = 1
C = Vla1
'*******************************************************************************
'Installation and conservation in eeprom mc, shutdown Q1
Cls
Ay = 0
X1 = D
Do
If X1 > 80 Then X1 = 49
If X1 < 49 Then X1 = 80
Locate 1 , 1
Lcd "[ ©cż.ł»a¶˝ocż¸]"
Locate 2 , 1
Lcd "B»a¶. łĂş».: " ; X1 ; " "
Ââĺđő_âíčç
Vla2 = X1
Loop Until Ay = 1
D = Vla2
Gosub Ńîőđŕĺíčĺ_äŕííűő
'***
Ńîőđŕĺíčĺ_äŕííűő:
Writeeeprom A , Ae ' we save variable A in nonvolatile memory of the microprocessor
Writeeeprom B , Be ' we save variable B in nonvolatile memory of the microprocessor
Writeeeprom C , Ce ' we save variable C in nonvolatile memory of the microprocessor
Writeeeprom D , De ' we save variable D in nonvolatile memory of the microprocessor
Return
'***
'*******************************************************************************
'Procedure to have charge of entering data, increase and de-emphasis
Sub Ââĺđő_âíčç()
Waitms 300
If Up = 0 Then Incr X1
If Down = 0 Then Decr X1
If Ok = 0 Then : Ay = 1 : Else : : Ay = 0 : End If
End Sub
'***
'*******************************************************************************
'The Procedure to have charge of on and off. Tr. under given in íŕńňđîęéęŕő, temperature
Sub Íŕăđĺâ
Tem1 = A
Tem2 = B
If T => Tem2 Then : Q2 = 0 : End If
If T <= Tem1 Then : Q2 = 1 : End If
End Sub
'*******************************************************************************
'The Procedure to have charge of on and off. Tr. under given in íŕńňđîęéęŕő, moisture
Sub Ôĺí
Vla1 = C
Vla2 = D
If H => Vla1 Then : Q1 = 1 : End If
If H <= Vla2 Then : Q1 = 0 : End If
End Sub
|