Sterownik pieca, kod z dmuchawą


'************* Konfiguracja uC *****************

'***********************************************

$regfile = "m8def.dat"

$crystal = 16000000

'Config Porta = &B00111111 : Porta = &B11111111

Config Portb = &B11111000 : Portb = &B11111111

Config Portc = &B11111111 : Portc = &B11111111

Config Portd = &B00011111 : Portd = &B11111111

Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5 'mirley UPT M16

Config Lcd = 16 * 2

Deflcdchar 0 , 7 , 5 , 7 , 32 , 32 , 32 , 32 , 32 'stopien

Deflcdchar 1 , 3 , 2 , 2 , 2 , 2 , 2 , 2 , 3 'nawias[

Deflcdchar 2 , 24 , 8 , 8 , 8 , 8 , 8 , 8 , 24 'nawias]

Cls

Cursor Off Noblink

Config 1wire = Pind.2

Sw_port Alias Pinb 'nazwa portu

Pompa Alias Portd.3

Went Alias Portd.4

Buzz Alias Portd.1

Light Alias Portd.0

Ds1r Alias Pind.7

Ds2r Alias Pind.6

Ds3r Alias Pind.5

Led_a Alias Portb.5

Led_p Alias Portb.3

Led_w Alias Portb.4

Config Timer0 = Timer , Prescale = 256

Enable Timer0 : On Timer0 Prztimer0

Enable Interrupts

'********** Konfiguracja uC Koniec ************

'****************** Zmienne *******************

'***********************************************

Dim Stan_sw As Byte , Sw As Byte , Licznik_sw As Byte 'sw

Dim Wyswietlanie As Byte , Poz_wysw As Byte , Wyswietlono As Bit 'Lcd

Dim Mig As Bit , Poz_ust As Byte

Dim Autosave As Byte , Autopowrot As Byte , Autolight As Byte

Dim Ds1(8) As Byte , Ds2(8) As Byte , Ds3(8) As Byte , Ds4(8) As Byte , Ds(8) As Byte , Ds_adr As Byte , Ds_ok As Bit 'DS18B20

Dim Ktory_ds As Byte , Lsb As Byte , Msb As Byte , Minusy As Byte

Dim T(4) As Word

Dim T_min As Word , T_alarm As Word

Dim Dmuch As Byte , Przerwa As Word

Dim Dzielnik(2) As Byte 'dzielniki timera

Dim Flaga_4ms As Bit , Flaga_500ms As Bit , Flaga_1s As Bit 'flagi przerwań

Dim Hbyte(2) As Byte , Hword(3) As Word , N As Byte , Hbit As Bit , M As Byte

Dim Buzz_en As Bit

Dim Tryb_letni As Bit '0- tryb zimowy, 1- tryb letni

Dim Wygaszenie As Bit , Praca_przerwa As Bit

Dim Licznik_went As Word , Tryb_pracy As Bit 'przerywany czy ciagly

Dim Wygasz_licz As Byte , Off_licz As Byte , Oldt1 As Word

'************* Zmienne Koniec ****************

'************ Warunki Poczatkowe ***************

'***********************************************

Light = 0

Lcd " Sterownik C.O."

Lowerline

Lcd " Wersja 1.04"

Wait 1

If Ds1r = 1 And Ds2r = 0 And Ds3r = 0 Then

Ds_adr = 30

Gosub Ds_reg

Cls

Lcd "Ds Piec"

End If

If Ds1r = 0 And Ds2r = 1 And Ds3r = 0 Then

Ds_adr = 40

Gosub Ds_reg

Cls

Lcd "Ds Bojler"

End If

If Ds1r = 1 And Ds2r = 1 And Ds3r = 0 Then

Ds_adr = 50

Gosub Ds_reg

Cls

Lcd "Ds Zbiornik"

End If

If Ds1r = 0 And Ds2r = 0 And Ds3r = 1 Then

Ds_adr = 60

Gosub Ds_reg

Cls

Lcd "Ds Kuchnia"

End If

For N = 1 To 8

Hbyte(1) = 30 + N

Readeeprom Ds1(n) , Hbyte(1)

Hbyte(1) = 40 + N

Readeeprom Ds2(n) , Hbyte(1)

Hbyte(1) = 50 + N

Readeeprom Ds3(n) , Hbyte(1)

Hbyte(1) = 60 + N

Readeeprom Ds4(n) , Hbyte(1)

Next N

Readeeprom T_min , 2

Readeeprom T_alarm , 4

Readeeprom Hbyte(1) , 6

Readeeprom Dmuch , 7

Readeeprom Przerwa , 8

Tryb_letni = Hbyte(1).0

If T_min < 100 Or T_min > 950 Then T_min = 400

If T_alarm < 100 Or T_alarm > 950 Then T_alarm = 850

If Dmuch < 2 Or Dmuch > 99 Then Dmuch = 10

If Przerwa < 60 Or Przerwa > 5940 Then Przerwa = 600

Hword(1) = Przerwa / 60

Hword(1) = Hword(1) * 60

If Przerwa <> Hword(1) Then Przerwa = 600

Wait 1

'start watch dog

Wygaszenie = 1 'standardowo wentylator nie pracuje

Wyswietlono = 1

Wyswietlanie = 1

Autosave = 5

Autolight = 0

'******* Warunki Poczatkowe Koniec ***********

'************** Petla glowna ******************

'***********************************************

Do

'*********************************************** co 4ms

If Flaga_4ms = 1 Then

Flaga_4ms = 0

Gosub Przyciski

If Wyswietlono = 1 Then Gosub Wysw_lcd

End If

'***********************************************

'*********************************************** co 500ms

If Flaga_500ms = 1 Then

Flaga_500ms = 0

Mig = Not Mig

If Pompa = 0 Then Led_p = Mig Else Led_p = 1

If Went = 0 Then Led_w = Mig Else Led_w = 1

Led_a = Buzz

Wyswietlanie = Poz_wysw

End If

'***********************************************

'*********************************************** co 1s

If Flaga_1s = 1 Then

Flaga_1s = 0

If Light = 0 Then

Incr Autolight

If Autolight >= 20 Then Light = 1

Else

Autolight = 0

End If

If Poz_wysw <> 1 Then

Incr Autopowrot

If Autopowrot = 6 Then

'Poz_wysw = 1

Wyswietlanie = 1

Poz_ust = 0

End If

Else

Autopowrot = 0

End If

If Autosave < 5 Then

Incr Autosave

If Autosave = 5 Then

'tu zapis do eeprom

Writeeeprom T_min , 2 '2 bajty

Writeeeprom T_alarm , 4 '2 bajty

Hbyte(1) = 0

Hbyte(1).0 = Tryb_letni

Writeeeprom Hbyte(1) , 6 'bajt

Writeeeprom Dmuch , 7 'bajt

Writeeeprom Przerwa , 8 '2 bajty

Poz_ust = 0

End If

End If

Gosub Temperatura

Gosub Sterowanie

End If

'***********************************************

Loop

End

'************ Petla glowna Koniec **************

'************ Przerwanie timer 0 ***************

'***********************************************

Prztimer0:

Timer0 = 5

Set Flaga_4ms

Incr Dzielnik(1)

If Dzielnik(1) = 125 Then

Dzielnik(1) = 0

Set Flaga_500ms

Incr Dzielnik(2)

If Dzielnik(2) = 2 Then

Dzielnik(2) = 0

Set Flaga_1s

End If

End If

Return

'******** Przerwanie timer 0 Koniec ************

'***********************************************

'***************** Przyciski **************

Przyciski:

Sw = Sw_port And &B00000111 'maska na piny nieużywane jako sw

If Sw <> &B00000111 And Stan_sw = Sw Then

Incr Licznik_sw

If Licznik_sw = 68 Then

Licznik_sw = 0

Select Case Stan_sw

Case &B00000011: 'incr

'***********************************************************

Select Case Poz_wysw

Case 3:

Select Case Poz_ust

Case 0:

Poz_ust = 1

Case 1:

If T_min < 950 Then T_min = T_min + 10

Case 2:

If T_alarm < 950 Then T_alarm = T_alarm + 10

End Select

Autosave = 0

Case 4:

If Poz_ust = 0 Then Poz_ust = 1 Else Tryb_letni = Not Tryb_letni

Autosave = 0

Case 5:

Select Case Poz_ust

Case 0:

Poz_ust = 1

Case 1:

If Dmuch < 99 Then Dmuch = Dmuch + 1

Case 2:

If Przerwa < 5940 Then Przerwa = Przerwa + 60

End Select

Autosave = 0

End Select

If Buzz = 0 Then Buzz_en = 0

Autopowrot = 0

Light = 0

Autolight = 0

Case &B00000101: 'ustaw next

'***********************************************************

If Poz_ust = 0 Then

Wyswietlanie = Poz_wysw + 1

If Wyswietlanie = 6 Then Wyswietlanie = 1

Else

Select Case Poz_wysw

Case 3:

Incr Poz_ust

If Poz_ust = 3 Then Poz_ust = 0

Case 4:

Incr Poz_ust

If Poz_ust = 2 Then Poz_ust = 0

Case 5:

Incr Poz_ust

If Poz_ust = 3 Then Poz_ust = 0

End Select

End If

If Buzz = 0 Then Buzz_en = 0

Autopowrot = 0

Light = 0

Autolight = 0

Case &B00000110: 'decr

'***********************************************************

Select Case Poz_wysw

Case 1:

Off_licz = 0

Tryb_pracy = 0

Wygaszenie = Not Wygaszenie

Case 3:

Select Case Poz_ust

Case 0:

Poz_ust = 1

Case 1:

If T_min > 100 Then T_min = T_min - 10

Case 2:

If T_alarm > 100 Then T_alarm = T_alarm - 10

End Select

Autosave = 0

Case 4:

If Poz_ust = 0 Then Poz_ust = 1 Else Tryb_letni = Not Tryb_letni

Autosave = 0

Case 5:

Select Case Poz_ust

Case 0:

Poz_ust = 1

Case 1:

If Dmuch > 2 Then Dmuch = Dmuch - 1

Case 2:

If Przerwa > 60 Then Przerwa = Przerwa - 60

End Select

Autosave = 0

End Select

If Buzz = 0 Then Buzz_en = 0

Autopowrot = 0

Light = 0

Autolight = 0

End Select

End If

Else

Stan_sw = Sw

Licznik_sw = 60

End If

Return

'***********************************************

'***********************************************

'************** LCD ***********

Wysw_lcd:

If Wyswietlanie <> 0 Then

Wyswietlono = 0

Select Case Wyswietlanie

Case 1: 'temp piec bojler

'**************************************************************

If Poz_wysw <> 1 Then

Cls

Lcd "Piec:"

Lowerline

Lcd "Bojler:"

End If

For N = 1 To 2

Hword(1) = T(n) / 10

Hword(2) = 12

If Hword(1) >= 10 Then Decr Hword(2)

If Hword(1) >= 100 Then Decr Hword(2)

If Minusy.n = 1 Then Decr Hword(2)

Locate N , Hword(2)

Hword(2) = T(n) Mod 10

If Minusy.n = 1 Then Lcd "-"

Lcd Hword(1) ; "." ; Hword(2) ; Chr(0) ; "C"

Next N

Case 2: 'temb banka,dom

'**************************************************************

If Poz_wysw <> 2 Then

Cls

Lcd "Zbiornik:"

Lowerline

Lcd "Kuchnia:"

End If

For N = 3 To 4

Hword(1) = T(n) / 10

Hword(2) = 12

If Hword(1) >= 10 Then Decr Hword(2)

If Hword(1) >= 100 Then Decr Hword(2)

If Minusy.n = 1 Then Decr Hword(2)

M = N - 2

Locate M , Hword(2)

Hword(2) = T(n) Mod 10

If Minusy.n = 1 Then Lcd "-"

Lcd Hword(1) ; "." ; Hword(2) ; Chr(0) ; "C"

Next N

Case 3:

'**************************************************************

If Poz_wysw <> 3 Then

Cls

Lcd "T.Min:"

Lowerline

Lcd "T.Alarm:"

End If

If Poz_ust = 1 And Mig = 1 Then

Locate 1 , 10

Lcd " "

Else

't minimalna

Hword(1) = T_min / 10

Hword(2) = 12

If Hword(1) >= 10 Then Decr Hword(2)

If Hword(1) >= 100 Then Decr Hword(2)

Locate 1 , Hword(2)

Hword(2) = T_min Mod 10

Lcd Hword(1) ; "." ; Hword(2) ; Chr(0) ; "C "

End If

If Poz_ust = 2 And Mig = 1 Then

Locate 2 , 10

Lcd " "

Else

't alarmowa

Hword(1) = T_alarm / 10

Hword(2) = 12

If Hword(1) >= 10 Then Decr Hword(2)

If Hword(1) >= 100 Then Decr Hword(2)

Locate 2 , Hword(2)

Hword(2) = T_alarm Mod 10

Lcd Hword(1) ; "." ; Hword(2) ; Chr(0) ; "C"

End If

Case 4:

'**************************************************************

If Poz_wysw <> 4 Then

Cls

Lcd "Tryb: "

End If

Locate 1 , 7

If Poz_ust = 1 And Mig = 1 Then

Lcd " "

Else

If Tryb_letni = 1 Then Lcd "Letni" Else Lcd "Zimowy"

End If

Case 5:

'**************************************************************

If Poz_wysw <> 5 Then

Cls

Lcd "Nadmuch:"

Lowerline

Lcd "Przerwa:"

End If

'dmuch

If Poz_ust = 1 And Mig = 1 Then

Locate 1 , 10

Lcd " "

Else

Hword(2) = 11

If Dmuch >= 10 Then Decr Hword(2)

Locate 1 , Hword(2)

Lcd Dmuch ; Chr(1) ; "s" ; Chr(2)

End If

'Przerwa

If Poz_ust = 2 And Mig = 1 Then

Locate 2 , 10

Lcd " "

Else

Hword(2) = 11

Hword(1) = Przerwa / 60

If Hword(1) >= 10 Then Decr Hword(2)

Locate 2 , Hword(2)

Lcd Hword(1) ; Chr(1) ; "min" ; Chr(2)

End If

End Select

Poz_wysw = Wyswietlanie

Wyswietlanie = 0

Wyswietlono = 1

End If

Return

'************** LCD Koniec ***********

'********** rejestracja DS *********

Ds_reg:

Disable Interrupts

1wreset

1wwrite &H33

Ds(1) = 1wread(8):

Enable Interrupts

If Ds(1) <> 255 Or Ds(2) <> 255 Or Ds(3) <> 255 Or Ds(4) <> 255 Or Ds(5) <> 255 Or Ds(6) <> 255 Or Ds(7) <> 255 Or Ds(8) <> 255 Then

Ds_ok = 1

For N = 1 To 8

Hbyte(1) = Ds_adr + N

Writeeeprom Ds(n) , Hbyte(1)

Next N

Else

Ds_ok = 0

End If

Return

'****** rejestracja DS Koniec ******

'************* Temperatura ***********

Temperatura:

Disable Interrupts

1wreset

Select Case Ktory_ds

Case 0:

1wwrite &HCC

1wwrite &H44

Case 1:

1wwrite &H55

1wwrite Ds1(1) , 8

1wwrite &HBE

Lsb = 1wread():

Msb = 1wread():

Case 2:

1wwrite &H55

1wwrite Ds2(1) , 8

1wwrite &HBE

Lsb = 1wread():

Msb = 1wread():

Case 3:

1wwrite &H55

1wwrite Ds3(1) , 8

1wwrite &HBE

Lsb = 1wread():

Msb = 1wread():

Case 4:

1wwrite &H55

1wwrite Ds4(1) , 8

1wwrite &HBE

Lsb = 1wread():

Msb = 1wread():

End Select

Enable Interrupts

If Ktory_ds > 0 Then

T(ktory_ds) = Msb * 256

T(ktory_ds) = T(ktory_ds) + Lsb

Minusy.ktory_ds = Msb.7

If Minusy.ktory_ds = 1 Then

T(ktory_ds) = Not T(ktory_ds)

T(ktory_ds) = T(ktory_ds) + 1

End If

T(ktory_ds) = T(ktory_ds) * 10

T(ktory_ds) = T(ktory_ds) / 16

Else

If Poz_wysw = 1 And Wyswietlono = 1 Then Wyswietlanie = 1

End If

Incr Ktory_ds

If Ktory_ds = 5 Then Ktory_ds = 0

Return

'********** Temperatura Koniec *********

'************ Sterowanie ***************

'***********************************************

Sterowanie:

If Tryb_letni = 1 Then

'letni

If T(1) >= T_min Then 'wlacza sie przy t_min

Hword(1) = T(2) + 70

Hword(2) = T(2) + 30

If T(1) >= Hword(1) Then Pompa = 0 'wlacza sie pompa jesli na piecu t większe o 7 stopni niz bojler

If T(1) <= Hword(2) Then Pompa = 1 'wylacza kiedy gdy na piecu t większe o mniej niż 3 stopnie

Else

Hword(1) = T_min - 30

If T(1) < Hword(1) Then Pompa = 1

End If

Else

'zimowy

If T(1) >= T_min Then

Pompa = 0

Else

Hword(1) = T_min - 30

If T(1) < Hword(1) Then Pompa = 1

End If

End If

'alarm

If T(1) >= T_alarm Or T(2) >= T_alarm Then

If Buzz_en = 1 Then Buzz = Not Buzz Else Buzz = 1

Else

Buzz = 1

Hword(1) = T_alarm - 50

If T(1) <= Hword(1) And T(2) <= Hword(1) Then Buzz_en = 1

End If

'wentylator

If T(1) >= T_min Then

If Tryb_pracy = 0 Then 'jeœli był ciagly to zmien tryb na przerywany i resetuj zmienne

Tryb_pracy = 1

Licznik_went = 0

Praca_przerwa = 0

End If

Else

Hword(1) = T_min - 30

If T(1) < Hword(1) Then

If Tryb_pracy = 1 Then

Tryb_pracy = 0

Off_licz = 0

End If

End If

End If

If Wygaszenie = 0 Then

If Tryb_pracy = 0 Then

Went = 0

Incr Wygasz_licz

If Wygasz_licz = 250 Then '250

Wygasz_licz = 0 'co okolo 4min

If Oldt1 >= T(1) Then

Incr Off_licz

If Off_licz = 8 Then Wygaszenie = 1

Else

If Off_licz > 0 Then Decr Off_licz

End If

Oldt1 = T(1)

End If

Else

If Praca_przerwa = 0 Then 'przerwa

Went = 1

Incr Licznik_went

If Licznik_went >= Przerwa Then

Licznik_went = 0

Praca_przerwa = 1

End If

Else

Went = 0

Incr Licznik_went

If Licznik_went >= Dmuch Then

Licznik_went = 0

Praca_przerwa = 0

End If

End If

End If

Else

Went = 1

End If

Return

'******** Sterowanie Koniec ************



Wyszukiwarka

Podobne podstrony:
2011 01 Prosty sterownik pieca c o
Dobór parametrów oraz elementów układu sterowania pieca
054 NissanPrimeraP10 Naprawa plytki sterowania dmuchawa
MB kod usterki w sterowniku poduszek powietrznych
KOD RAMKA OBRAZ GLITEROWY DMUCHAWCE I TEKST
054 NissanPrimeraP10 Naprawa plytki sterowania dmuchawa
Układy Napędowe oraz algorytmy sterowania w bioprotezach
PODSTAWY STEROWANIA SILNIKIEM INDUKCYJNYM
Sterowce
WYKŁAD 02 SterowCyfrowe
04) Kod genetyczny i białka (wykład 4)
1 kod kresk
wykład 4 Sterowanie zapasami
Sterowniki PLC
Hazardy sterowania

więcej podobnych podstron