Code:
$regfile = "m8def.dat"
$crystal = 3686400
$hwstack = 256
$swstack = 256
$framesize = 256
'***************************Config Schaltausgänge*******************************
Config Portb = Output
Brenner Alias Portb.3
Pumpefb Alias Portb.4
Pumpehk Alias Portb.5
'**************************Def. allgemeiner Variabeln***************************
Dim Tagnacht As Bit
Dim Nachtbetrieb As Byte
Dim Tagbetrieb As Byte
Dim Tempmessstelle(8) As Single
Dim Brennerstarts As Integer
Dim Interrupt_brenner As Bit
Dim Zeit_in_min As Integer
Dim Kessel_max As Single
Dim Kessel_min As Single
Dim Kessel_grenz_max As Single
Dim Kessel_grenz_min As Single
Dim Delta_kessel As Single
Dim Delta_vl_rl_fb As Single
Dim Wassertemp As Bit
Dim Aussentemp As Single
Dim Flag_aussentemp As Bit
Aussentemp = 2.68
Dim Flag_frequenz As Bit
Flag_frequenz = 0
Kessel_max = 57.0 '60.0
Kessel_min = 40.0 '43.0
Kessel_grenz_max = Kessel_max
Kessel_grenz_min = Kessel_min
Wassertemp = 1
Brennerstarts = 0
Interrupt_brenner = 0
Nachtbetrieb = 22
Tagbetrieb = 4
Const Tagtemp_og = 21.8
Const Tagtemp_ug = 21.6
Const Nachttemp_og = 21.4
Const Nachttemp_ug = 21.2
'**************************Funktionen LCD-Display*******************************
Config Lcd = 40 * 4
Config Lcdpin = Pin , Rs = Portb.0 , Db4 = Portd.5 , Db5 = Portd.4 , Db6 = Portd.3 , Db7 = Portd.2 , E = Portd.6 , E2 = Portd.7
Config Lcdbus = 4
Config Lcdmode = Port
Dim ___lcdno As Byte
___lcdno = 0
Initlcd
Cursor Off
Cls
___lcdno = 1
Initlcd
Cursor Off
Cls
'*******************************************************************************
Config 1wire = Portc.1 'DS1820
Match_rom Alias &H55
Read_scratchpad Alias &HBE
Start_conversion Alias &H44
Innen Alias 0
Vorlauf_fb Alias 1
Rücklauf_fb Alias 2
Vorlauf_hk Alias 3
Kessel Alias 4
Dim Read_temp As Integer
Dim Sensor_ids(48) As Byte
Dim Id As Byte
Dim Offset As Byte
Dim Ds_array(7) As Byte
Dim Bruchteil As Single
Dim Temperatur As Single
Dim I As Integer
'*************************Config INT0 zur Frequenzmesung************************
Enable Interrupts
Enable Int0
Config Int0 = Falling
Dim Flankenzahl As Integer
Flankenzahl = 0
On Int0 Irq
'*************************Config Timer1*****************************************
Config Timer1 = Timer , Prescale = 256 '256 '64 '256 'Konfiguriere Timer1
Enable Timer1 'schalte den Timer1 ein
On Timer1 Isr_von_timer1 'verzweige bei Timer1 überlauf zu Isr_von_Timer1
Enable Interrupts
Timer1 = 51135 'Timer1 soll schon von 34285 wegzählen
'***************************Config RTC******************************************
Config Sda = Portc.4
Config Scl = Portc.5
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
Config Clock = User ' this will dim the bytes automatic
Dim Weekday As Byte
'Time$ = "01:50:00" ' to watch the day changing value
Date$ = "10.28.07" ' erstmaliges stellen der Uhr
'Weekday = 7
'***************************AD-Config*******************************************
Config Adc = Single , Prescaler = Auto
Dim Faktor As Single
Dim Sp As Integer
Faktor = 5.28 / 1023
'***************************ID 1Wire configurieren******************************
For Id = 1 To 40 'Einlesen der 5 Sensoren IDs (5*8 Byte)
I = Id - 1
Readeeprom Sensor_ids(id) , I
Next Id
'**************************Initialisierung**************************************
Brenner = 0
Pumpefb = 1
Pumpehk = 1
'**************************Hauptrogramm*****************************************
Do
Waitms 1000
For Id = Innen To Kessel 'Kessel
Offset = Id * 8
Offset = Offset + 1 'Offset geht auf 1, 9, 17, 25 und 33
1wreset 'hier wird der Temperaturwert eingelesen
1wwrite Match_rom
1wwrite Sensor_ids(offset) , 8 '8 Byte ID wird übertragen
1wwrite Read_scratchpad
For I = 1 To 7 'nur bis 7, weil 8 und 9 uninteressant
Ds_array(i) = 1wread()
Next I
Read_temp = Makeint(ds_array(1) , Ds_array(2))
1wreset 'jetzt wird wieder die Konvertierung gestartet
1wwrite Match_rom
1wwrite Sensor_ids(offset) , 8
1wwrite Start_conversion
Shift Read_temp , Right
If 127 < Read_temp Then Read_temp = Read_temp - 32768
Bruchteil = 16 - Ds_array(7)
Bruchteil = Bruchteil / 16
Bruchteil = Bruchteil - 0.25
Temperatur = Read_temp + Bruchteil
If Temperatur >= -16.0 Then
Tempmessstelle(id + 1) = Read_temp + Bruchteil 'Temperatur
End If
___lcdno = 0
Locate 1 , 2 : Lcd "BO-U RA-T KE-T VLB-T RLB-T"
Select Case Id
Case Innen: '1
Locate 2 , 7 : Lcd Fusing(tempmessstelle(1) , "#.#")
Locate 2 , 11 : Lcd " "
Case Kessel: '2
Locate 2 , 12 : Lcd Fusing(tempmessstelle(2) , "#.#")
Locate 2 , 16 : Lcd " "
Case Vorlauf_fb: '3
Locate 2 , 17 : Lcd Fusing(tempmessstelle(3) , "#.#")
Locate 2 , 21 : Lcd " "
Case Rücklauf_fb: '4
Locate 2 , 23 : Lcd Fusing(tempmessstelle(4) , "#.#")
Locate 2 , 27 : Lcd " "
End Select
Locate 2 , 6 : Lcd " "
If Tempmessstelle(8) >= 0 Then
Locate 2 , 2 : Lcd Fusing(tempmessstelle(8) , "#.##")
Else
Locate 2 , 1 : Lcd Fusing(tempmessstelle(8) , "#.#")
End If
___lcdno = 1
Locate 2 , 20
Lcd Time$
Locate 2 , 15 : Lcd " "
Select Case Id
Case Vorlauf_hk: '5
Locate 1 , 1 : Lcd "Vl-hk " : Lcd Fusing(tempmessstelle(5) , "#.#")
Locate 1 , 11 : Lcd " "
End Select
'Locate 1 , 12 : Lcd "AU-T " : Lcd Fusing(tempmessstelle(7) , "#.##")
Locate 1 , 12 : Lcd "AU-T " : Lcd Fusing(aussentemp , "#.##")
Locate 1 , 21 : Lcd " "
Locate 2 , 1 : Lcd "Starts:" '"B-Start: "
Locate 2 , 9 : Lcd Brennerstarts 'Brennerstarts
Locate 2 , 16
Lcd Weekday
Cursor Off
Next Id
If _hour >= Nachtbetrieb Or _hour < Tagbetrieb Then 'Or _hour = 7 Or _hour = 8 Then
Tagnacht = 0 'Nachteinstellung
Else
Tagnacht = 1 'Tageinstellung
End If
Gosub Ad_wandler
Gosub Überwachung_kesseltemp 'Aussentemp_mittel
Gosub Schalterelais
Gosub Aussentemp_mittel
Gosub Kesselgrenzwert
'Gosub Überwachung_pumpen
If Wassertemp = 0 Then
Gosub Überwachung_brauchwassertemp
End If
Loop
End
'*******************************Uhr stellen + 1min******************************
Uhr_plus_min:
Return
'*******************************Frequenzzähler**********************************
Frequenz:
Return
'*******************************Überwachung Brauchwassertemp********************
Überwachung_brauchwassertemp:
If Tempmessstelle(4) <= 42.0 Then
Wassertemp = 0
If Tempmessstelle(2) < 48.0 Then
Brenner = 1
End If
If Tempmessstelle(2) > 58.0 Then
Brenner = 0
End If
Pumpehk = 1
Pumpefb = 0
End If
If Tempmessstelle(2) >= 50 Then
Wassertemp = 1
End If
Return
'*******************************Überwachung Pumpen******************************
Überwachung_pumpen:
If Tempmessstelle(2) < 29.0 Then
Pumpefb = 0
End If
If Tempmessstelle(2) >= 32.0 Then
Pumpefb = 1
End If
If Tempmessstelle(2) < 38.0 Then
Pumpehk = 0
End If
If Tempmessstelle(2) >= 36.0 Then
Pumpehk = 1
End If
Return
'*******************************AD-Wandler**************************************
Ad_wandler:
Start Adc
Sp = Getadc(0)
Tempmessstelle(8) = Sp * Faktor
'Tempmessstelle(8) = Tempmessstelle(8) - 0.35
'Tempmessstelle(8) = 132.14 * Tempmessstelle(8)
'Tempmessstelle(8) = Tempmessstelle(8) - 153.93 ' Boiler_temp unten
Sp = Getadc(2)
Tempmessstelle(7) = Sp * Faktor ' Außentemp
'Sp = Getadc(2)
'Tempmessstelle(6) = Sp * Faktor
Return
'
'**************************Überwachung Kesseltemp*******************************
Überwachung_kesseltemp:
If Tempmessstelle(2) >= Kessel_grenz_max Or Tempmessstelle(8) >= 1.52 Then
Brenner = 0
If Interrupt_brenner = 0 Then
Brennerstarts = Brennerstarts + 1
Interrupt_brenner = 1
End If
End If
If Tempmessstelle(2) < Kessel_grenz_min And Tempmessstelle(8) <= 1.46 Then
Brenner = 1
Interrupt_brenner = 0
End If
Return
'*************************Kesselgrenzwert bestimmen*****************************
Kesselgrenzwert:
If Aussentemp > 1.8 And Aussentemp < 3.0 Then
If Aussentemp >= 2.68 Then ' Aussentemp >= 18 Grad
Delta_kessel = 0
End If
If Aussentemp > 2.10 And Aussentemp < 2.68 Then
Delta_kessel = 2.68 - Aussentemp
Delta_kessel = Delta_kessel * 11
Delta_kessel = Abs(delta_kessel)
End If
If Aussentemp <= 2.10 Then 'Aussentemp <= -7 Grad
Delta_kessel = 0.58 * 11
End If
End If
Return
'*************************Mittelwert der Außentemp******************************
Aussentemp_mittel:
'If _min = 0 Then
Aussentemp = Tempmessstelle(7) + Aussentemp
Aussentemp = Aussentemp / 2
'End If
Return
'*************************Sub Relais schalten***********************************
Schalterelais:
Select Case Tagnacht
Case 0
Gosub Nachtbetrieb
Case 1
Gosub Tagbetrieb
End Select
Return
'**************************Sub für Tagbetrieb**********************************
Tagbetrieb:
'If Weekday = 6 Or Weekday = 7 Then
' If _hour <= 8 Then
'' Kessel_grenz_min = Kessel_min
' Kessel_grenz_max = Kessel_max + Delta_kessel
' Else
' Kessel_grenz_min = Kessel_min + Delta_kessel
' Kessel_grenz_max = Kessel_max + Delta_kessel
' End If
'Else
If _hour <= 12 Then
Kessel_grenz_min = Kessel_min
Kessel_grenz_max = Kessel_max + Delta_kessel
Else
Kessel_grenz_min = Kessel_min + Delta_kessel
Kessel_grenz_max = Kessel_max + Delta_kessel
End If
'End If
If Tempmessstelle(1) <= Tagtemp_ug Then
Pumpefb = 1
End If
If Tempmessstelle(1) >= Tagtemp_og Then
Brenner = 0
Pumpefb = 0
End If
Return
'**************************Sub für Nachtbetrieb*********************************
Nachtbetrieb:
Kessel_grenz_min = 29.0
If Tempmessstelle(2) >= Kessel_grenz_min Then
Brenner = 0
Pumpefb = 1
Else
Brenner = 0
Pumpefb = 0
End If
If _hour = 0 Then 'Brennerstarts auf Null setzen
Brennerstarts = 0
Delta_kessel = 0
Aussentemp = 2.68
End If
Return
'***************************INTO Interrupt**************************************
Irq:
Incr Flankenzahl
Return '
'**************************Subroutine für Timer1*******************************
Isr_von_timer1: 'ISR von Timer1
Timer1 = 51135
Flankenzahl = 0
Return
'***************************Subs für RTC****************************************
Getdatetime:
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' start address in 1307
I2cstart ' Generate start code
I2cwbyte Ds1307r ' send address
I2crbyte _sec , Ack
I2crbyte _min , Ack ' MINUTES
I2crbyte _hour , Ack ' Hours
I2crbyte Weekday , Ack ' Day of Week
I2crbyte _day , Ack ' Day of Month
I2crbyte _month , Ack ' Month of Year
I2crbyte _year , Nack ' Year
I2cstop
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return
Setdate:
_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 Data to SECONDS
I2cwbyte _month ' MINUTES
I2cwbyte _year ' Hours
I2cstop
Return
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
'*******************************************************************************
$eeprom
Data &H10 , &HE8 , &HF4 , &H23 , &H01 , &H08 , &H00 , &HEF ' 0
Data &H10 , &H1B , &HD0 , &H23 , &H01 , &H08 , &H00 , &H23 ' 1
Data &H10 , &H78 , &H37 , &H39 , &H01 , &H08 , &H00 , &H11 ' 2
Data &H10 , &HC0 , &H46 , &H19 , &H01 , &H08 , &H00 , &H67 ' 3
'Data &H10 , &HBD , &HB6 , &H23 , &H01 , &H08 , &H00 , &H40 ' 4
Data &H10 , &H56 , &HA3 , &H23 , &H01 , &H08 , &H00 , &H3F ' 5
Lesezeichen