$regfile = “m168def.dat” $crystal = 8000000 $baud = 9600 Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2 Config Lcd = 20 * 4 ‘configure lcd screen Cls ‘need to remove line -test ‘=================================VARIABLES============ Config Portb = Output Beep Alias Pinb.0 ‘– sound Heater Alias Pinb.1 ‘– heater activate signal Feeder Alias Pinb.2 ‘– food feeder activate signal Light Alias Pinb.3 ‘– light lamp activate signal Config Portc.0 = Input ‘——- Thermo-sensor input Thermo Alias Portc.0 Config Portc.2 = Input ‘button corr + But1 Alias Pinc.2 Config Portc.3 = Input ‘button corr - But2 Alias Pinc.3 Config Portc.4 = Input ‘button SET But3 Alias Pinc.4 Config Portc.1 = Input ‘water level sensor Level Alias Pinc.1 Config Adc = Single , Prescaler = Auto ‘— adc for thermometer Start Adc ‘[====================now init the clock] 86400sec=24h Config Date = Dmy , Separator = / ‘ ANSI-Format Config Clock = Soft ‘——–this is how simple it is Dim Lsecofday As Long ‘— Initial Data of time Dim Timetmp As Long ‘—– TEMP time date Enable Interrupts _day = 01 : _month = 01 : _year = 09 ‘Alarm1 ‘——- Feed timer1 ‘Alarm2 ‘——- Feed timer1 ‘Alarm3 ‘—— Light timer ON ‘Alarm4 ‘—— Light timer Off ‘Alarm5 ‘—- Feeder 1stop ‘Alarm6 ‘—- Feeder 2stop Dim Alarm(6) As Long ‘———————- Dim R1 As Integer , R2 As Integer , R3 As Integer ‘Read ADC PORTC.0 ‘calc temterature ‘-Temp Sensor ADC value Dim Foodc As Long ‘—— FOOD DAY COUNTER in sec = 1Day=86400 Foodc = 86410 Dim Feed_on As Byte ‘——- Feed Motor On/Off statur Dim Feed_sec As Byte ‘——— Feed Motor work cycle in sec Dim Menu As Byte ‘- menu line Menu = 1 Dim Setup As Byte ‘ SET Enable Dim Curon As Byte , Curup As Byte , Curdn As Byte ‘– cursor on 1-on 0-off ‘– cursor up 1-on 0-off ‘– cursor dn 1-on 0-off Dim A As Integer ‘ cycle counter Dim B As Byte ‘ cycle counter Dim C As Byte ‘ cycle counter Dim I As Byte ‘ cycle counter Dim E As Integer ‘ cycle counter, Alarm duration, and monitor Dim Rec As Integer ‘— cycle EEPROM REC Dim Soundt As Byte ‘— sound notification for temp Dim Temp As Single , Con As Byte ‘—- temperature celsius, con=const –CON=100 Dim Tmonitor As String * 5 ‘— monitor temp Dim Tc As String * 4 ‘– array to convert temp from NUMERIC to STR Dim T(5) As Integer ‘– array1 for temp calc Dim T1(5) As Integer ‘– array2 for temp calc Dim Tset As Byte ‘———– Temp Adjust value for Heater Dim Heat As Byte ‘——– Heater is On/Of Dim Heat_c1 As Long ‘——– Counter of Heater Start in (Sec) Dim Heat_c2 As Long ‘——– Counter of Heater Stop in (Sec) Dim Heat_cnt As Integer ‘——– Full Counter of Heater in (Sec) Dim Kw_heat As Integer ‘——- Power consumption in during work time kW Dim Pow_heat As Byte ‘——- Heater Power consumption W Pow_heat = 100 Dim Light_on As Byte ‘———- Light Lamp On/Off ‘========================== SUB PROG Dim S As Byte Declare Sub Timeset Declare Sub Food_cnt Declare Sub Termo_menu Declare Sub Thermo_read Declare Sub Timer_set ‘——– Special chars Deflcdchar 0 , 10 , 10 , 5 , 5 , 10 , 20 , 20 , 10 ‘ heat ‘Deflcdchar 1 , 31 , 10 , 17 , 17 , 17 , 31 , 31 , 31 ‘ Level Deflcdchar 1 , 4 , 14 , 17 , 23 , 21 , 21 , 14 , 32 ‘ Timer Deflcdchar 2 , 32 , 1 , 2 , 32 , 10 , 4 , 18 , 4 ‘ feed1 Deflcdchar 3 , 1 , 32 , 5 , 2 , 21 , 32 , 10 , 18 ‘ feed2 Deflcdchar 4 , 9 , 2 , 20 , 4 , 18 , 1 , 9 , 1 ‘ lamp1 Deflcdchar 5 , 18 , 8 , 5 , 4 , 9 , 16 , 18 , 16 ‘ lamp2 Deflcdchar 6 , 1 , 3 , 29 , 21 , 21 , 29 , 3 , 1 ‘ sound on Deflcdchar 7 , 17 , 11 , 29 , 23 , 23 , 29 , 11 , 17 ‘ sound off ‘============================== MAIN PROG ‘Locate 1 , 1 : Lcd “Aqua Controll v3.3? Print Chr(254) ; Chr(128); Print “Aqua Controll v3.3? Print Chr(254) ; Chr(192); Print “Author: ......” ‘Locate 2 , 1 : Lcd “.....” ‘======================= READ EEPROM DATA Readeeprom Soundt , 1 Readeeprom Lsecofday , 5 Readeeprom Foodc , 10 Readeeprom Alarm(1) , 15 Readeeprom Alarm(2) , 20 Readeeprom Alarm(3) , 25 Readeeprom Alarm(4) , 30 Readeeprom Con , 35 Readeeprom Tset , 36 Readeeprom Heat_cnt , 40 Readeeprom Feed_sec , 45 If Con > 254 Then Foodc = 86400 Soundt = 1 Alarm(1) = 60 Alarm(2) = 120 Alarm(3) = 240 Alarm(4) = 3600 Con = 100 Tset = 25 Writeeeprom Tset , 36 Heat_cnt = 0 Writeeeprom Heat_cnt , 40 Feed_sec = 10 End If Alarm(5) = Alarm(1) + Feed_sec Alarm(6) = Alarm(2) + Feed_sec Date$ = Date(lsecofday) Time$ = Time(lsecofday) ‘—————— Wait 1 Sound Beep , 400 , 555 Cursor Off Cls Do Gosub Thermo_read ‘—————————- CHOSE MENU If But1 = 0 And But2 = 0 And Curon = 0 Then ‘———- MENU ENTER Curon = 1 : Sound Beep , 400 , 550 : Sound Beep , 300 , 250 : Menu = 1 : Waitms 350 End If If But1 = 0 And But2 = 0 And Curon = 1 Then ‘———- MENU EXIT Curon = 0 : Setup = 0 : Sound Beep , 400 , 250 : Sound Beep , 300 , 550 : Menu = 1 : Waitms 150 End If If Curon = 1 And But2 = 0 And Menu 1 Then ‘—– CURSOR DN Sound Beep , 20 , 350 Curup = 0 : Curdn = 1 : Decr Menu End If If But3 = 0 And Curon = 1 And Setup = 0 Then ‘——— ENTER SETUP For A = 1000 To 400 Step -200 Sound Beep , 30 , A Next A Setup = 1 End If If But3 = 0 Then ‘——- ENTER TO ADVANCED MENU after keep But3 3sec Incr B If B = 7 Then Gosub Adv_menu End If End If ‘————————— Print Date Lsecofday = Syssec() If Curon = 1 And Menu = 1 Then If Setup = 1 Then S = 0 : Gosub Timeset End If Locate 1 , 1 : Lcd “>” ; Time(lsecofday) Else Locate 1 , 1 : Lcd Time(lsecofday) ; ” ” End If ‘————————— Print Time Locate 1 , 13 : Lcd Date(lsecofday) ; Timetmp = Dayofweek() Select Case Timetmp Case 0 Locate 1 , 10 : Lcd “Mo” Case 1 Locate 1 , 10 : Lcd “Tu” Case 2 Locate 1 , 10 : Lcd “We” Case 3 Locate 1 , 10 : Lcd “Th” Case 4 Locate 1 , 10 : Lcd “Fr” Case 5 Locate 1 , 10 : Lcd “Sa” Case 6 Locate 1 , 10 : Lcd “Su” End Select ‘ Locate 1 , 10 : Lcd Secofday() ; ” ” ; ‘Locate 1 , 10 : Lcd Heat_cnt ; ” ” ; ‘————————————————————- Thermal status If Temp < 18 Then Tmonitor = “Cold ” If Soundt = 1 Then Sound Beep , 100 , 220 End If End If If Temp = 18 Then Tmonitor = “Low ” If Soundt = 1 And E = 15 Then Sound Beep , 100 , 350 : Sound Beep , 100 , 1200 : Sound Beep , 100 , 350 End If End If If Temp 23.5 Then Tmonitor = “Norm ” If Temp >= 27 And Temp 30 And Temp 33 Then Tmonitor = “Hight” Sound Beep , 500 , 220 End If ‘——————————— Print To Screen THERMO DATA If Curon = 1 And Menu = 2 Then If Setup = 1 Then Gosub Termo_menu End If Locate 2 , 1 : Lcd “>t=” ; Left(tc , 4) ; Chr(223) ; ” ” Else Locate 2 , 1 : Lcd “t=” ; Left(tc , 4) ; Chr(223) ; ” ” End If If R3 < 340 Then ‘— no signal alarm Locate 2 , 3 : Lcd “No Signal”; Sound Beep , 100 , 220 Sound Beep , 70 , 450 If Heat = 1 Then Heat = 0 : Heater = 1 ‘————- HEATER OFF in case if no signal from thermo End If Else Locate 2 , 8 : Lcd Tmonitor; ‘————- HEATER CONTROLL A = Int(temp ) : Incr A ‘————- HEATER ON If A Tset And Heat = 1 Then Heat_c2 = Syssec() Timetmp = Heat_c2 - Heat_c1 Heat_cnt = Heat_cnt + Timetmp Writeeeprom Heat_cnt , 40 Heat = 0 : Heater = 1 End If End If ‘——— Sound On Off If Curon = 1 And Menu = 3 Then If Setup = 1 And Soundt = 0 Then Soundt = 1 : Setup = 0 : Writeeeprom Soundt , 1 End If If Setup = 1 And Soundt = 1 Then Soundt = 0 : Setup = 0 : Writeeeprom Soundt , 1 End If Locate 2 , 13 : Lcd “>” Else Locate 2 , 13 : Lcd ” ” End If If Soundt = 1 Then Locate 2 , 14 : Lcd Chr(6) Else Locate 2 , 14 : Lcd Chr(7) End If ‘————————————————— Print Water level If Level = 1 Then Locate 2 , 19 : Lcd Chr(219) ; Else Locate 2 , 19 : Lcd Chr(214) ; End If ‘———— Level check Alarm If Level = 0 And Soundt = 1 And E = 20 Then Locate 2 , 19 : Lcd “_” ; Sound Beep , 300 , 600 End If ‘————————————————— Print Food reminder ‘ Food_day = Sysday(foodc) - Syssec() If Curon = 1 And Menu = 4 Then If Setup = 1 Then Gosub Food_cnt End If Locate 3 , 1 : Lcd “>Food_end=” ; Date(foodc) ; ” ” Else Locate 3 , 1 : Lcd “Food_end=” ; Date(foodc) ; ” ” End If ‘——- Sound Alarm, Food empty If Soundt = 1 And E = 25 Then Timetmp = Syssec() If Timetmp > Foodc Then Locate 3 , 1 : Lcd “Food_end=” ; “**/**/**” Sound Beep , 15 , 1500 Sound Beep , 20 , 777 Sound Beep , 23 , 455 End If End If ‘——- print timers If E >= 49 Or E = 1000 Then Rec = 0 Locate 2 , 15 : Lcd Chr(235); Lsecofday = Syssec() Writeeeprom Lsecofday , 5 Writeeeprom Foodc , 10 Else Locate 2 , 15 : Lcd ” “; End If Incr Rec C = E / 10 Tmonitor = Time(alarm(c)) If C = 1 Then Locate 4 , 1 : Lcd “Feeding 1 On:” End If If C = 2 Then Locate 4 , 1 : Lcd “Feeding 2 On:” End If If C = 3 Then Locate 4 , 1 : Lcd “Light is On: ” End If If C = 4 Then Locate 4 , 1 : Lcd “Light is Off:” End If Locate 4 , 14 : Lcd Chr(1) ; “=” ; Left(tmonitor , 5) Incr E ‘————————————————— Timers Data If Curon = 1 And Menu = 5 Then If Setup = 1 Then Gosub Timer_set End If Locate 4 , 15 : Lcd “>” ; End If ‘———- Timers control Gosub Timer_mon: ‘===SPC If Heat = 1 Then Locate 2 , 12 : Lcd Chr(0) : Waitms 20 End If ‘== SPC If Light_on = 1 Then Locate 2 , 16 : Lcd Chr(4) ; Chr(5) End If ‘===SPC If Feed_on = 1 Then Locate 2 , 20 : Lcd Chr(2) Waitms 300 Locate 2 , 20 : Lcd Chr(3) Waitms 300 Else Locate 2 , 20 : Lcd ” “; End If Loop ‘=========================================================================================== Main LOOP END Adv_menu: For A = 200 To 800 Step 200 Sound Beep , 100 , A Next A B = 0 : Cls Kw_heat = Heat_cnt / 3600 Kw_heat = Kw_heat * Pow_heat ‘ Kw_heat = Kw_heat / 100 Locate 1 , 1 : Lcd “Heater Coun=” ; Kw_heat ; ” Wh” Kw_heat = Kw_heat / 1000 Locate 2 , 1 : Lcd “Heater Coun=” ; Kw_heat ; ” kWh” Do If But1 = 0 And But2 = 0 Then Sound Beep , 150 , A Waitms 400 Cls Return End If Loop Return Timer_mon: ‘———- Timer Monitoring ‘——– Food Timetmp = Secofday() If Timetmp = Alarm(1) Or Timetmp = Alarm(2) And Feed_on = 0 Then Sound Beep , 450 , 1000 Feeder = 1 : Feed_on = 1 ‘———- Feed Motor ON, reset counter End If If Timetmp = Alarm(5) Or Timetmp = Alarm(6) And Feed_on = 1 Then Sound Beep , 450 , 550 Feeder = 1 : Feed_on = 0 ‘——- Feed motor off End If ‘——- Light If Alarm(3) Alarm(3) And Timetmp Alarm(4) And Timetmp > Alarm(3) And Light_on = 1 Then ‘———- Light Off Sound Beep , 400 , 1350 Light = 1 : Light_on = 0 Locate 2 , 16 : Lcd ” ” End If Else If Timetmp > Alarm(3) And Timetmp > Alarm(4) And Light_on = 0 Then ‘———- Light On Sound Beep , 400 , 1350 Light = 1 : Light_on = 1 End If If Timetmp > Alarm(4) And Timetmp < Alarm(3) And Light_on = 1 Then ‘———- Light Off Sound Beep , 400 , 1350 Light = 1 : Light_on = 0 Locate 2 , 16 : Lcd ” ” End If End If Return ‘———————– Setup Timers Sub Timer_set Cls E = 1 : Menu = 1 : Curon = 1 : Setup = 0 Locate 1 , 1 : Lcd ” Feed Light ” Locate 2 , 2 : Lcd “1-” : Locate 2 , 12 : Lcd “On -” Locate 3 , 2 : Lcd “2-” : Locate 3 , 12 : Lcd “Off-” Locate 4 , 2 : Lcd “Dur(s)-” Do ‘— choosing items If Curon = 1 And But2 = 0 And Menu 1 And Setup = 0 Then ‘—– CURSOR DN Sound Beep , 20 , 350 : Waitms 250 Curup = 0 : Curdn = 1 : Decr Menu End If ‘— enter/exit setup mode If But3 = 0 And Setup = 1 Then Setup = 0 : Sound Beep , 250 , 1150 : Sound Beep , 400 , 250 : Waitms 250 End If If But3 = 0 And Setup = 0 Then Setup = 1 : Sound Beep , 250 , 250 : Sound Beep , 400 , 1150 : Waitms 250 End If If But1 = 0 And Setup = 1 Then ‘—– set UP Sound Beep , 20 , 350 : Waitms 50 If Menu = 5 And Feed_sec 86400 Then Alarm(menu) = 0 End If Alarm(menu) = Alarm(menu) + A Goto Skp1 End If If But2 = 0 And Setup = 1 Then ‘—– set DN Sound Beep , 20 , 450 : Waitms 50 If Menu = 5 And Feed_sec > 0 Then Decr Feed_sec : Goto Skp1 End If A = E * 60 : Incr E If Alarm(menu) ” Case 2 Locate 2 , 11 : Lcd ” ” Locate 2 , 1 : Lcd ” ” Locate 3 , 1 : Lcd “>” Case 3 Locate 3 , 1 : Lcd ” ” Locate 3 , 11 : Lcd ” ” Locate 2 , 11 : Lcd “>” Case 4 Locate 4 , 1 : Lcd ” ” Locate 2 , 11 : Lcd ” ” Locate 3 , 11 : Lcd “>” Case 5 Locate 3 , 11 : Lcd ” ” Locate 4 , 1 : Lcd “>” End Select Tmonitor = Time(alarm(1)) Locate 2 , 4 : Lcd Left(tmonitor , 5) Tmonitor = Time(alarm(2)) Locate 3 , 4 : Lcd Left(tmonitor , 5) Tmonitor = Time(alarm(3)) Locate 2 , 16 : Lcd Left(tmonitor , 5) Tmonitor = Time(alarm(4)) Locate 3 , 16 : Lcd Left(tmonitor , 5) Locate 4 , 9 : Lcd Feed_sec ; ” ” If But1 = 0 And But2 = 0 Then ‘———– EXIT PARENT MERNU Sound Beep , 110 , 850 Sound Beep , 500 , 450 Setup = 0 : Menu = 5 : Cls Alarm(5) = Alarm(1) + Feed_sec Alarm(6) = Alarm(2) + Feed_sec Writeeeprom Alarm(1) , 15 Writeeeprom Alarm(2) , 20 Writeeeprom Alarm(3) , 25 Writeeeprom Alarm(4) , 30 Writeeeprom Feed_sec , 45 Waitms 200 Return End If Locate 4 , 13 : Lcd Time(lsecofday) ; Loop End Sub ‘———————- Thermal MENU Sub Termo_menu Cls B = 1 : E = 0 : C = 0 Locate 1 , 1 : Lcd “Current Cor Target” ‘Locate 3 , 1 : Lcd “Push SET enter setup” ‘Locate 4 , 1 : Lcd “Push To Exit” Do If But1 = 0 And But2 = 0 Then ‘———– EXIT PARENT MERNU Sound Beep , 110 , 850 Sound Beep , 500 , 450 Setup = 0 : Cls Writeeeprom Con , 35 Writeeeprom Tset , 36 Waitms 300 Return End If If But1 = 0 And B = 1 Then Sound Beep , 10 , 450 B = 2 : Waitms 50 End If If But2 = 0 And B = 2 Then Sound Beep , 10 , 1250 B = 1 : Waitms 50 End If If But1 = 0 And E 0 Then Sound Beep , 10 , 450 If E = 1 Then : Incr Con : End If If E = 2 Then : Incr Tset : End If Waitms 10 End If If But2 = 0 And E 0then Sound Beep , 10 , 1250 If E = 1 Then : Decr Con : End If If E = 2 Then : Decr Tset : End If Waitms 10 End If If But3 = 0 And E = 0 And B = 1 Then ‘———- SET UP MODE curr E = 1 : C = 70 : B = 0 Sound Beep , 110 , 850 Sound Beep , 500 , 450 End If If But3 = 0 And E = 0 And B = 2 Then ‘———- SET UP MODE target E = 2 : C = 70 : B = 3 Sound Beep , 110 , 850 Sound Beep , 500 , 450 End If If But3 = 0 And E 0 Then ‘———– EXIT SETUP MODE E = 0 : C = 10 If B = 0 Then B = 1 If B = 3 Then B = 2 Sound Beep , 500 , 450 Sound Beep , 110 , 850 End If If B = 1 Or B = 0 Then Locate 2 , 1 : Lcd ” ” : Waitms C Locate 2 , 1 : Lcd “>t=” ; Left(tc , 4) ; Chr(223) ; ” ” Locate 2 , 14 : Lcd ” t=” ; Tset ; Chr(223) ; ” ” Elseif B = 2 Or B = 3 Then Locate 2 , 1 : Lcd ” t=” Locate 2 , 15 : Lcd ” ” : Waitms C Locate 2 , 14 : Lcd “>t=” ; Tset ; Chr(223) ; ” ” End If Locate 2 , 10 : Lcd Con ; ” ” Gosub Thermo_read Loop End Sub ‘————————- FOOD REMINDER COUNTER DAYS Sub Food_cnt Foodc = Syssec() Waitms 200 Do If But1 = 0 Then Sound Beep , 110 , 450 Foodc = Foodc + 86400 Waitms 100 End If If But2 = 0 And Foodc >= 172800 Then Sound Beep , 110 , 1250 Foodc = Foodc - 86400 Waitms 100 End If If But3 = 0 Then ‘—– EXIT For A = 400 To 1000 Step 200 Sound Beep , 50 , A Next A Setup = 0 Writeeeprom Foodc , 10 Waitms 400 Return End If Locate 3 , 1 : Lcd ” ” ; Waitms 40 Locate 3 , 1 : Lcd “>Food_days=” ; Date(foodc) ; ” ” Waitms 80 Loop End Sub ‘=================================== TIME DATE SETUP Sub Timeset: Menu = 1 : Setup = 0 Cls Locate 2 , 1 : Lcd “HH:MM:SS DD/MM/YY” Sound Beep , 400 , 550 Do ‘————————- EXIT SETUP If But1 = 0 And But2 = 0 Then For A = 400 To 1000 Step 200 Sound Beep , 50 , A Next A Writeeeprom Lsecofday , 5 Heat_cnt = 0 Setup = 0 Waitms 400 Cls : Menu = 1 Date$ = Date(lsecofday) Time$ = Time(lsecofday) Return End If ‘——choose pos If But3 = 0 Then Sound Beep , 10 , 250 : Waitms 200 Incr Menu If Menu > 6 Then Menu = 1 End If End If If But1 = 0 Or But2 = 0 Then Sound Beep , 15 , 250 End If Select Case Menu Case 1 Locate 1 , 1 : Lcd ” ” ‘———————– CURSOR UP If But1 = 0 Then Incr _hour End If ‘———————— CURSOR DN If But2 = 0 Then Decr _hour End If Case 2 Locate 1 , 4 : Lcd ” ” ‘———————– CURSOR UP If But1 = 0 Then Incr _min End If ‘———————— CURSOR DN If But2 = 0 Then Decr _min End If Case 3 Locate 1 , 7 : Lcd ” ” ‘———————– CURSOR UP If But1 = 0 Then Incr _sec End If ‘———————— CURSOR DN If But2 = 0 Then Decr _sec End If Case 4 Locate 1 , 12 : Lcd ” ” ‘———————– CURSOR UP If But1 = 0 Then Incr _day End If ‘———————— CURSOR DN If But2 = 0 Then Decr _day End If Case 5 Locate 1 , 15 : Lcd ” ” ‘———————– CURSOR UP If But1 = 0 Then Incr _month End If ‘———————— CURSOR DN If But2 = 0 Then Decr _month End If Case 6 Locate 1 , 18 : Lcd ” ” ‘———————– CURSOR UP If But1 = 0 Then Incr _year End If ‘———————— CURSOR DN If But2 = 0 Then Decr _year End If End Select Waitms 80 Lsecofday = Syssec() Locate 1 , 1 : Lcd Time(lsecofday) Locate 1 , 12 : Lcd Date(lsecofday) Waitms 80 Loop End Sub ‘—————————- THERMAL SENSOR READ Sub Thermo_read For A = 1 To 5 For I = 1 To 5 ‘–Read RC 5 times R1 = Getadc(0) T(i) = R1 R2 = R2 + T(i) Waitms 5 Next I R2 = R2 / 6 ‘— calculate meddle T1(a) = R2 R3 = R3 + T1(a) ‘–Read RC 5 times from middle Next A R3 = R3 / 6 ‘—— final RC value ‘====================================== Calculation Degrees Celsius table Temp = R3 - 335 Temp = Temp - Con ‘— def 435 Temp = Temp / 9 Temp = Temp + 18 Tc = Str(temp) ‘——- FINAL VALUE OF TEMP End Sub ‘===== END End