$regfile = "m32def.dat"
$crystal = 8000000
$hwstack = 128
$swstack = 128
$framesize = 128
$baud = 9600
$include "Config_MMC.bas"
$include "Config_AVR-DOS.BAS"
Declare Sub Srednik
Config Pinb.0 = Input
Config Pinb.1 = Input
Config Pinb.2 = Input
Config Pinb.3 = Input
Config Porta.0 = Output
Config Porta.1 = Output
Config Porta.2 = Output
Config 1wire = Portd.7
Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5
Config Lcd = 20 * 4
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Compare B Pwm = Disconnect , Prescale = 1
Config Clock = Soft , Gosub = Sectic
Config Date = Dmy , Separator = /
Dim Temp1_lcd As String * 6
Dim Temp2_lcd As String * 6
Dim Tempmin_lcd As String * 6
Dim Tempmax_lcd As String * 6
Dim Tempminsd_lcd As String * 6
Dim Tempmaxsd_lcd As String * 6
Dim Tempamplituda_lcd As String * 6
Dim Srednia_lcd As String * 6
Dim Data_sd As String * 8
Dim Flaga_zapisz As Bit
Dim Flaga_zapisz_sr As Bit
Dim Flaga_menu As Bit
Dim Flaga_1w As Bit
Dim Blad_sd As Bit
Dim Interwal As Byte
Dim Dsid1(8) As Byte
Dim Dsid2(8) As Byte
Dim Czujnik As Byte
Dim Errorcode As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Tempmin As Integer
Dim Tempmax As Integer
Dim Tempminsd As Integer
Dim Tempmaxsd As Integer
Dim Tempamplituda As Integer
Dim Czas As Integer
Dim Srednia As Long
Dim Srednia_p As Long
Deflcdchar 1 , 12 , 18 , 18 , 12 , 32 , 32 , 32 , 32 ' Stopnie
Deflcdchar 2 , 32 , 7 , 15 , 31 , 31 , 31 , 31 , 31
Deflcdchar 3 , 32 , 4 , 4 , 4 , 4 , 21 , 14 , 4 ' replace ? with number (0-7)
Deflcdchar 4 , 4 , 14 , 21 , 4 , 4 , 4 , 4 , 32 ' replace ? with number (0-7)
S1 Alias Pinb.0
S2 Alias Pinb.1
S3 Alias Pinb.2
S4 Alias Pinb.3
Led1 Alias Porta.0
Led2 Alias Porta.1
Led3 Alias Porta.2
Set Porta.0
Set Porta.1
Set Porta.2
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3
Time$ = "06:00:01"
Date$ = "01.01.10"
Flaga_zapisz = 0
Tempmin = 1000
Tempmax = -1000
Interwal = 3
Dsid2(1) = 1wsearchfirst()
Dsid1(1) = 1wsearchnext()
Interwal = 1
Cursor Off
Cls
Enable Interrupts
Wait 4
Pwm1a = 50
Do
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Flaga_menu = 1
Cls
Locate 1 , 8
Lcd "Czas "
Wait 2
Do
Locate 3 , 6
Lcd Time$
Waitms 500
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
_sec = 0
Czas = 0
Srednia = 0
Incr _min
If _min = 60 Then
_min = 0
End If
End If
End If
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
_sec = 0
Czas = 0
Srednia = 0
Incr _hour
If _hour = 24 Then
_hour = 0
End If
End If
End If
Loop Until S4 = 0
Cls
Locate 1 , 8
Lcd "DATA "
Wait 3
Do
Locate 3 , 6
Lcd Date$
Waitms 500
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
Incr _day
If _day = 31 Then
_day = 0
End If
End If
End If
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr _month
If _month = 12 Then
_month = 12
End If
End If
End If
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Incr _year
If _year = 20 Then
_year = 10
End If
End If
End If
Loop Until S4 = 0
Cls
Locate 1 , 6
Lcd "INTERWAL"
Wait 2
Do
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
Incr Interwal
If Interwal = 4 Then
Interwal = 1
End If
End If
End If
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Decr Interwal
If Interwal = 0 Then
Interwal = 3
End If
End If
End If
Locate 3 , 1
Select Case Interwal
Case 1 : Lcd "1 sekunda "
Case 2 : Lcd "1 minuta "
Case 3 : Lcd "10 minut "
End Select
Waitms 500
Loop Until S4 = 0
Locate 1 , 6
Lcd "EXIT MENU"
If Tempmax = 850 Then
Tempmax = -1000
End If
Waitms 600
Srednia_p = 0
Srednia = 0
Czas = 0
Flaga_menu = 0
Cls
End If
End If
If Flaga_zapisz = 1 Then
If Flaga_menu = 0 Then
Gbdriveerror = Driveinit()
If Gbdriveerror = 0 Then
Errorcode = Initfilesystem(1)
If Errorcode <> 0 Then
Blad_sd = 1
Else
Led2 = 0
Waitms 5
Led2 = 1
Open "temper.txt" For Append As #2
Write #2 , Date$ , Time$ , Temp1_lcd , Temp2_lcd
Flush #2
Close #2
Led3 = 0
Waitms 5
Led3 = 1
If Flaga_zapisz_sr = 1 Then
Waitms 50
Led2 = 0
Waitms 5
Led2 = 1
Open "avg.txt" For Append As #1
Write #1 , Data_sd , Tempminsd_lcd , Tempmaxsd_lcd , Tempamplituda_lcd , Srednia_lcd
Flush #1
Close #1
Led3 = 0
Waitms 5
Led3 = 1
Flaga_zapisz_sr = 0
End If
Flaga_zapisz = 0
Select Case Interwal
Case 1:
Waitms 1
Case 2:
Wait 2
Case 3:
Wait 2
End Select
End If
Else
Locate 2 , 1
Lcd "blad"
End If
End If
End If
Loop
Sectic:
Led1 = 0
Czujnik = 1wirecount()
1wreset
1wwrite &H55
1wverify Dsid1(1)
1wwrite &HBE
Temp1 = 1wread(2)
1wreset
1wwrite &H55
1wverify Dsid2(1)
1wwrite &HBE
Temp2 = 1wread(2)
1wreset
1wwrite &HCC
1wwrite &H44
Temp1 = Temp1 * 10
Temp1 = Temp1 \ 16
Temp2 = Temp2 * 10
Temp2 = Temp2 \ 16
If Temp1 < Tempmin Then
Tempmin = Temp1
Tempminsd = Temp1
End If
If Temp1 > Tempmax Then
Tempmax = Temp1
Tempmaxsd = Temp1
End If
Tempamplituda = Tempmaxsd - Tempminsd
Temp1_lcd = Str(temp1)
Temp1_lcd = Format(temp1_lcd , "0.0")
Temp2_lcd = Str(temp2)
Temp2_lcd = Format(temp2_lcd , "0.0")
Tempmin_lcd = Str(tempmin)
Tempmin_lcd = Format(tempmin_lcd , "0.0")
Tempmax_lcd = Str(tempmax)
Tempmax_lcd = Format(tempmax_lcd , "0.0")
Tempminsd_lcd = Str(tempminsd)
Tempminsd_lcd = Format(tempminsd_lcd , "0.0")
Tempmaxsd_lcd = Str(tempmaxsd)
Tempmaxsd_lcd = Format(tempmaxsd_lcd , "0.0")
Tempamplituda_lcd = Str(tempamplituda)
Tempamplituda_lcd = Format(tempamplituda_lcd , "0.0")
If S1 = 0 Then
Tempmin = 1000
Tempmax = -1000
End If
Led1 = 1
Gosub Srednik
Select Case Interwal
Case 1:
Flaga_zapisz = 1
Case 2:
If _sec = 0 Then
Flaga_zapisz = 1
End If
Case 3:
If _min = 0 Or _min = 10 Or _min = 20 Or _min = 30 Or _min = 40 Or _min = 50 Then
If _sec = 0 Then
Flaga_zapisz = 1
End If
End If
End Select
If Flaga_menu = 0 Then
Locate 1 , 1
Lcd Time$ ; " "
Locate 1 , 12
Lcd Date$
Locate 2 , 1
Lcd "Out:" ; Temp1_lcd ; Chr(1) ; "C " ; "Avg:" ; Srednia_lcd ; Chr(1) ; "C "
Locate 3 , 1
Lcd "In :" ; Temp2_lcd ; Chr(1) ; "C "
Locate 4 , 1
Lcd Chr(3) ; ":" ; Tempmin_lcd ; Chr(1) ; "C "
Locate 4 , 11
Lcd Chr(4) ; ":" ; Tempmax_lcd ; Chr(1) ; "C "
End If
Return
Srednik:
If _sec = 0 And _min = 59 And _hour = 23 Then
Data_sd = Date$
End If
If _sec = 0 Then
Incr Czas
Srednia_p = Srednia_p + Temp1
Srednia = Srednia_p / Czas
Srednia_lcd = Str(srednia)
Srednia_lcd = Format(srednia_lcd , "0.0")
End If
If _sec = 0 And _min = 0 And _hour = 0 Then
Flaga_zapisz_sr = 1
Srednia_p = 0
Srednia = 0
Czas = 0
Tempminsd = 1000
Tempmaxsd = -1000
Tempamplituda = 0
End If
Return