Już nie mam pomysłu jak to zrobić, proszę tylko o jakieś rozwiązanie, znajdzie się ktoś taki na elektrodzie, kto potrafi programować w Bascom'ie i pomoże rozwiązać mój problem...Próbowałem różnych sposobów z flagami i innymi cudami, ale ciągle to nie jest to.
Proszę o pomoc!
...a i jeszcze jedno pytanie:
Dlaczego gdy mam przerwanie uruchomione to wylatuje wyświetlacz LCD, pojawiają się krzaczki i koniec trzeba zresetować sterownik. Jak myślicie co może być powodem???
Kod:
Kod: Zaznacz cały
'Data aktualizacji: 23 listopada 2010r.
$regfile = "m8535.DAT"
$crystal = 16000000
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.3 , Db6 = Portc.2 , Db7 = Portc.1 , E = Portc.5 , Rs = Portc.6
Config Lcd = 20 * 2
Config 1wire = Portc.0
Config Watchdog = 2048
Cls
Config Porta = Output
Reset Porta.0
Reset Porta.1
Reset Porta.2
Reset Porta.6
Reset Porta.7 'PortA jako wyjścia
Config Portb = Input 'PortB jako wejścia
Portb = 255
Config Portd.0 = Output
Portd.0 = 0
Config Portd.1 = Output
Portd.1 = 1
Config Portd.2 = Input
Config Portd.3 = Output
Portd.3 = 0
Config Portd.4 = Output
Portd.4 = 0
Config Portd.5 = Output
Portd.5 = 0
Config Portd.6 = Output
Portd.6 = 0
Config Portd.7 = Output
Portd.7 = 0
'Sterownik pieca C.O.
'zależności:
'Tp < Tn & Tp > 20st.C to zal. PK1
'Tp > 20st.C to zał. PK2
'Tb < Tp to zał. PK3
'Tk > Tb o dT1 pompa kręci się z prędkością P1 (20%)
'Tk > Tb o dT2 pompa kręci się z prędkością P2 (40%)
'Tk > Tb o dT3 pompa kręci się z prędkością P3 (60%)
'Tk > Tb o dT4 pompa kręci się z prędkością P4 (80%)
'Tk > Tb o dT5 pompa kręci się z prędkością P5 (100%)
Dim Keyup As Bit
Dim Keydown As Bit
Dim Keybcks As Bit
Dim Keyenter As Bit
Dim Menu As Byte
Dim P_conf_ds As Byte
Dim Keys As Byte
Dim X As Byte
Dim D_t1 As Integer 'parametr dT1
Dim D_t2 As Integer 'parametr dT2
Dim D_t3 As Integer 'parametr dT3
Dim D_t4 As Integer 'parametr dT4
Dim D_t5 As Integer
Dim D_t1_1 As Integer
Dim D_t2_2 As Integer
Dim D_t3_3 As Integer
Dim D_t4_4 As Integer
Dim D_t5_5 As Integer
Dim D_t1_1_1 As Integer 'parametr dT5
Dim E_d_t1_1 As Eram Integer
Dim E_d_t2_2 As Eram Integer
Dim E_d_t3_3 As Eram Integer
Dim E_d_t4_4 As Eram Integer
Dim E_d_t5_5 As Eram Integer
Dim E_tna As Eram Integer
Dim Temp As Integer
Dim Tp As Integer , Ss1 As String * 6
Dim Tb As Integer , Ss2 As String * 6
Dim Tk As Integer , Ss3 As String * 6
Dim Tn As Integer 'temp. pieca
Dim Dsid1(8) As Byte
Dim Dsid2(8) As Byte
Dim Dsid3(8) As Byte
Dim Edsid1(8) As Eram Byte At &H10
Dim Edsid2(8) As Eram Byte At &H20
Dim Edsid3(8) As Eram Byte At &H30
Dim Index As Byte
Dim Tpa As Integer 'temp. pieca
Dim Tka As Integer 'temp. kolektora
Dim Tba As Integer 'temp. bojlera
Dim Tna As Integer 'nastawa Tn
Dim B As Byte 'deklaracja zmiennej do odczytu kodów ID
Dim W As Byte
Dim A As Byte
Dim C As Byte
Dim Tk1 As Integer
Dim Tk2 As Integer
Dim Tk3 As Integer
Dim Tk4 As Integer
Dim Tk5 As Integer
Dim Tb1 As Integer
Dim Tb2 As Integer
Dim Tb3 As Integer
Dim Tb4 As Integer
Dim Tb5 As Integer
Dim Tp1 As Integer
Dim Tp11 As Integer
Dim Lcd_temp As Integer
Dim Moc As Word
Dim Table As Word
Dim Procent As Byte
Dim Flaga1 As Bit
Dim Flaga2 As Bit
Dim Flaga3 As Bit
Dim Flaga4 As Bit
Dim Tpp As Byte
Dim Tbb As Byte
Dim Tkk As Byte
Dim Buz As Byte
Key_bcks Alias Pinb.1
Key_up Alias Pinb.3
Key_down Alias Pinb.2
Key_enter Alias Pinb.0
Pk1 Alias Porta.0 'klapka (PK1)
Pk2 Alias Porta.1 'pompa - piec (PK2)
Pk3 Alias Porta.2 'zawór (PK3)
Tri1 Alias Porta.3 'pompa kolektorów (TRI1)
Tri2 Alias Porta.4 'wolny triak TRI2
Tri3 Alias Porta.5
'wolny triak TRI3
Buzzer Alias Porta.6
Set Buzzer
Wait 1
Reset Buzzer
Config Timer1 = Timer , Prescale = 64
Config Int0 = Change
Stop Timer1
On Timer1 Irq_timer1
On Int0 Zero
'detekcja przejścia przez 0
Enable Timer1
Enable Int0
Enable Interrupts
Moc = 0 'zacznij od 0% mocy
For Index = 1 To 8
Dsid1(index) = Edsid1(index)
Next Index
Index = 0
For Index = 1 To 8
Dsid2(index) = Edsid2(index)
Next Index
Index = 0
For Index = 1 To 8
Dsid3(index) = Edsid3(index)
Next Index
Index = 0
Deflcdchar 0 , 8 , 20 , 8 , 32 , 32 , 32 , 32 , 32 ' replace ? with number (0-7) 'znak stopnia Celsjusza
Deflcdchar 1 , 12 , 12 , 12 , 12 , 12 , 12 , 12 , 12 ' replace ? with number (0-7)
Deflcdchar 2 , 32 , 4 , 14 , 14 , 14 , 31 , 4 , 32 ' replace ? with number (0-7)
Deflcdchar 3 , 24 , 20 , 24 , 20 , 21 , 6 , 5 , 32 ' replace ? with number (0-7)
Cursor Off
Cls
Lcd " STEROWNIK " ;
Locate 2 , 6
Lcd "Pieca C.O."
Waitms 500
Cls
Locate 1 , 3
Lcd "Wersja programu:"
Locate 2 , 9
Lcd "1.10"
Waitms 500
'Cls
'ilość podpiętych czujnikow temperatury
'W = 1wirecount()
'Lcd "Ilosc czujnikow temp"
'Locate 2 , 9
'Lcd "-" ; W ; "-"
'Waitms 500
Cls
1wreset
1wwrite &HCC
1wwrite &H44
'Odczyt z pamięci EEprom parametrów
D_t1_1 = E_d_t1_1
D_t2_2 = E_d_t2_2
D_t3_3 = E_d_t3_3
D_t4_4 = E_d_t4_4
D_t5_5 = E_d_t5_5
D_t1 = D_t1_1 / 10
D_t2 = D_t2_2 / 10
D_t3 = D_t3_3 / 10
D_t4 = D_t4_4 / 10
D_t5 = D_t5_5 / 10
If D_t1 = 0 Then
D_t1 = 1
End If
If D_t2 = 0 Then
D_t2 = 2
End If
If D_t3 = 0 Then
D_t3 = 3
End If
If D_t4 = 0 Then
D_t4 = 4
End If
If D_t5 = 0 Then
D_t5 = 5
End If
If D_t1 = 1 Then
D_t1_1 = 10
End If
If D_t2 = 2 Then
D_t2_2 = 20
End If
If D_t3 = 3 Then
D_t3_3 = 30
End If
If D_t4 = 4 Then
D_t4_4 = 40
End If
If D_t5 = 5 Then
D_t5_5 = 50
End If
Tna = E_tna
Tn = Tna / 10
Cls
For Buz = 1 To 3
Set Buzzer
Waitms 100
Reset Buzzer
Waitms 100
Next Buz
Flaga4 = 1
Locate 1 , 7
Lcd Chr(2)
Do
For Index = 1 To 8
Dsid1(index) = Edsid1(index)
Next Index
Index = 0
For Index = 1 To 8
Dsid2(index) = Edsid2(index)
Next Index
Index = 0
For Index = 1 To 8
Dsid3(index) = Edsid3(index)
Next Index
Index = 0
'*****************************************
Stop Watchdog
If Key_enter = 0 Then
Gosub P_menu
Cls
End If
Start Watchdog
1wreset
1wwrite &H55
1wwrite Dsid1(1) , 8
1wwrite &H44
1wwrite &HBE
Waitms 400
1wreset
1wwrite &H55
1wwrite Dsid1(1) , 8
1wverify Dsid1(1)
If Err <> 1 Then
Flaga1 = 0
1wwrite &HBE
Tp = 1wread(2)
Tp = Tp * 10
Tp = Tp / 16
Ss1 = Str(tp)
Ss1 = Format(ss1 , " 0.0")
Else
Flaga1 = 1
Ss1 = "BRAK "
End If
Stop Watchdog
If Key_enter = 0 Then
Gosub P_menu
Cls
End If
Start Watchdog
'**********************Pomiar temp. - czujnik bojlera***************************
1wreset
1wwrite &H55
1wwrite Dsid2(1) , 8
1wwrite &H44
1wwrite &HBE
Waitms 400
1wreset
1wwrite &H55
1wwrite Dsid2(1) , 8
1wverify Dsid2(1)
If Err <> 1 Then
Flaga2 = 0
1wwrite &HBE
Tb = 1wread(2)
Tb = Tb * 10
Tb = Tb / 16
Ss2 = Str(tb)
Ss2 = Format(ss2 , " 0.0")
Else
Flaga2 = 1
Ss2 = "BRAK "
End If
Stop Watchdog
If Key_enter = 0 Then
Gosub P_menu
Cls
End If
Start Watchdog
'****************Pomiar temp. - czujnik kolektora słonecznego*******************
1wreset
1wwrite &H55
1wwrite Dsid3(1) , 8
1wwrite &H44
1wwrite &HBE
Waitms 400
1wreset
1wwrite &H55
1wwrite Dsid3(1) , 8
1wverify Dsid3(1)
If Err <> 1 Then
Flaga3 = 0
1wwrite &HBE
Tk = 1wread(2)
Tk = Tk * 10
Tk = Tk / 16
Ss3 = Str(tk)
Ss3 = Format(ss3 , " 0.0")
Else
Flaga3 = 1
Ss3 = "BRAK "
End If
Stop Watchdog
If Key_enter = 0 Then
Gosub P_menu
Cls
End If
Start Watchdog
Tna = E_tna
Tn = Tna / 10
Locate 1 , 1
Lcd "NP " ; Tn ; Chr(0) ;
Locate 1 , 11
Lcd Chr(1) ; "Boj " ; Ss2 ; Chr(0) ;
Locate 2 , 1
Lcd "Piec " ; Ss1 ; Chr(0) ;
Locate 2 , 11
Lcd Chr(1) ; "Kol " ; Ss3 ; Chr(0) ;
If Flaga4 = 1 Then
Locate 1 , 7
Lcd Chr(2)
End If
Tb1 = Tb + D_t1_1
Tb2 = Tb + D_t2_2
Tb3 = Tb + D_t3_3
Tb4 = Tb + D_t4_4
Tb5 = Tb + D_t5_5
If Flaga2 = 1 Or Flaga3 = 1 Then
Moc = 0
Locate 1 , 9
Lcd " "
Else
If Tk <= Tb Then
Moc = 0
End If
If Tk >= Tb1 Then
Moc = 1
End If
If Tk >= Tb2 Then
Moc = 2
End If
If Tk >= Tb3 Then
Moc = 3
End If
If Tk >= Tb4 Then
Moc = 4
End If
If Tk >= Tb5 Then
Moc = 5
End If
End If
If Flaga1 = 0 Then
If Tp < Tna Then 'pk1 = klapka
Set Pk1
End If
Tp1 = Tp - 10
If Tp1 > Tna Then
Reset Pk1
End If
Else
Reset Pk1
End If
If Tp > 250 Then 'pk2 = pompa pieca - liczba 200 -> 20 st.C (st.C * 10 = liczba z DS18B20 lub DS1822 )
Set Pk2
End If
If Tp < 240 Then
Reset Pk2
End If
If Flaga1 = 1 Or Flaga2 = 1 Then
Set Pk3
Else
If Tp1 > Tb Then
Set Pk3 'pk3 = zawór
End If
If Tp < Tb Then
Reset Pk3
End If
End If
If Moc = 0 Then
Locate 1 , 9
Lcd " "
End If
If Moc = 1 Then
Locate 1 , 9
Lcd Chr(3) ; "1"
End If
If Moc = 2 Then
Locate 1 , 9
Lcd Chr(3) ; "2"
End If
If Moc = 3 Then
Locate 1 , 9
Lcd Chr(3) ; "3"
End If
If Moc = 4 Then
Locate 1 , 9
Lcd Chr(3) ; "4"
End If
If Moc = 5 Then
Locate 1 , 9
Lcd Chr(3) ; "5"
End If
If Flaga4 = 0 Then
If Key_up = 0 And Key_down = 0 Then
Waitms 500
If Key_up = 0 And Key_down = 0 Then
Flaga4 = 1
Locate 1 , 7
Lcd Chr(2)
End If
End If
End If
If Flaga4 = 1 Then
If Key_up = 0 And Key_down = 0 Then
Wait 1
If Key_up = 0 And Key_down = 0 Then
Flaga4 = 0
Locate 1 , 7
Lcd " "
End If
End If
End If
If Flaga4 = 1 Then
If Flaga1 = 1 Or Flaga2 = 1 Or Flaga3 = 1 Then
Set Buzzer
End If
End If
If Flaga4 = 0 Then
Reset Buzzer
End If
If Flaga1 = 0 And Flaga2 = 0 And Flaga3 = 0 Then
Reset Buzzer
End If
Loop
P_menu:
Cls
Menu = 1
Do
If Key_up = 0 Then
Waitms 80
If Key_up = 0 Then 'wybranie nr menu 1-7 przyciskiem Up lub Down
Decr Menu
Cls
End If
End If
If Key_down = 0 Then
Waitms 80
If Key_down = 0 Then
Incr Menu
Cls
End If
End If
If Menu = 8 Then
Cls
Menu = 1
End If
If Menu = 0 Then
Cls
Menu = 7
End If
If Key_bcks = 0 Then 'jeżeli przycisk BCKS wciśnięty dłużej niż 400ms powrót do programu głównego
Waitms 400
If Key_bcks = 0 Then
Return
End If
End If
Select Case Menu
Case 1 : Locate 1 , 2
Lcd "Nastawa temp. Tn: "
Locate 2 , 10
Lcd Tn ; Chr(0)
If Key_enter = 0 Then
Waitms 400
If Key_enter = 0 Then
Temp = Tn
Gosub Nastawa
Tna = Temp * 10
Tn = Tna / 10
E_tna = Tna
End If
End If
'Case 2 : Locate 1 , 2
'Lcd "Nastawa temp. T1: "
'Locate 2 , 10
'Lcd D_t1 ; Chr(0) 'Po wybraniu parametru do zmiany wciskamy Enter, również następuje zapis do pamięci EEprom
' If Key_enter = 0 Then
' Waitms 400
' If Key_enter = 0 Then
'
' Temp = D_t1
' Gosub Nastawa
' D_t1_1 = Temp * 10
' D_t1 = D_t1_1 / 10
' E_d_t1_1 = D_t1_1
' End If
'End If
'Case 3 : Locate 1 , 2
'Lcd "Nastawa temp. T2: "
'Locate 2 , 10
'Lcd D_t2 ; Chr(0)
' If Key_enter = 0 Then
' Waitms 400
' If Key_enter = 0 Then
'
' Temp = D_t2
' Gosub Nastawa
' D_t2_2 = Temp * 10
' D_t2 = D_t2_2 / 10
' E_d_t2_2 = D_t2_2
' End If
' End If
'Case 4 : Locate 1 , 2
'Lcd "Nastawa temp. T3: "
'Locate 2 , 10
'Lcd D_t3 ; Chr(0)
' If Key_enter = 0 Then
' Waitms 400
' If Key_enter = 0 Then
'
' Temp = D_t3
' Gosub Nastawa
' D_t3_3 = Temp * 10
' D_t3 = D_t3_3 / 10
' E_d_t3_3 = D_t3_3
' End If
' End If
'Case 5 : Locate 1 , 2
'Lcd "Nastawa temp. T4: "
'Locate 2 , 10
'Lcd D_t4 ; Chr(0)
' If Key_enter = 0 Then
' Waitms 400
' If Key_enter = 0 Then
'
' Temp = D_t4
' Gosub Nastawa
' D_t4_4 = Temp * 10
' D_t4 = D_t4_4 / 10
' E_d_t4_4 = D_t4_4
' End If
' End If
'Case 6 : Locate 1 , 2
'Lcd "Nastawa temp. T5: "
'Locate 2 , 10
'Lcd D_t5 ; Chr(0)
' If Key_enter = 0 Then
' Waitms 400
' If Key_enter = 0 Then
' Temp = D_t5
' Gosub Nastawa
' D_t5_5 = Temp * 10
' D_t5 = D_t5_5 / 10
' E_d_t5_5 = D_t5_5
' End If
' End If
Case 7:
Locate 1 , 2
Lcd "Konfiguracja "
Locate 2 , 2
Lcd "czunikow temp."
If Key_enter = 0 Then
Waitms 400
If Key_enter = 0 Then
Gosub Conf_ds
End If
End If
End Select
Loop
Nastawa:
Cls
Do
If Key_up = 0 Then
Waitms 100
If Key_up = 0 Then
Incr Temp
End If
End If
If Key_down = 0 Then
Waitms 100
If Key_down = 0 Then
Decr Temp
End If
End If
Locate 1 , 4
Lcd "Ustaw wartosc:"
Locate 2 , 10
Lcd Temp ; Chr(0) ; " "
If Key_bcks = 0 Then 'jeżeli przycisk BCKS wciśnięty przez czas od 100ms - 399ms to powrót do Menu
Return
End If
Waitms 100
Loop
Conf_ds:
Cls
P_conf_ds = 1
Do
If Key_up = 0 Then
Waitms 80
If Key_up = 0 Then
Cls 'wybranie nr menu 1-7 przyciskiem Up lub Down
Decr P_conf_ds
Cls
End If
End If
If Key_down = 0 Then
Waitms 80
If Key_down = 0 Then
Cls
Incr P_conf_ds
Cls
End If
End If
If P_conf_ds = 4 Then
Cls
P_conf_ds = 1
End If
If P_conf_ds = 0 Then
Cls
P_conf_ds = 3
End If
If Key_bcks = 0 Then
Waitms 150
If Key_bcks = 0 Then
Cls
Return
End If
End If
Select Case P_conf_ds 'wybranie nr menu 1-3 przyciskiem Up lub Down
Case 1:
Locate 1 , 1
Lcd "Czujnik - piec: "
If Key_enter = 0 Then
Wait 1
If Key_enter = 0 Then
Gosub Conf_ds1
End If
End If
Case 2:
Locate 1 , 1
Lcd "Czujnik - bojler: "
If Key_enter = 0 Then
Wait 1
If Key_enter = 0 Then
Gosub Conf_ds2
End If
End If
Case 3:
Locate 1 , 1
Lcd "Czujnik - kolektor:"
If Key_enter = 0 Then
Wait 1
If Key_enter = 0 Then
Gosub Conf_ds3
End If
End If
End Select
Loop
Conf_ds1:
Cls
Dsid1(1) = 1wsearchfirst()
For Index = 1 To 8
Edsid1(index) = Dsid1(index)
Next Index
If Dsid1(8) = Crc8(dsid1(1) , 7) Then
Locate 1 , 1
Lcd "OK - Czujnik ID"
Wait 1
Locate 2 , 1
For B = 1 To 8
Lcd Hex(dsid1(b))
Next
End If
Wait 1
Return
Conf_ds2:
Cls
Dsid2(1) = 1wsearchfirst()
For Index = 1 To 8
Edsid2(index) = Dsid2(index)
Next Index
If Dsid2(8) = Crc8(dsid2(1) , 7) Then
Locate 1 , 1
Lcd "OK - Czujnik ID"
Wait 1
Locate 2 , 1
For B = 1 To 8
Lcd Hex(dsid2(b))
Next
End If
Wait 1
Return
Conf_ds3:
Cls
Dsid3(1) = 1wsearchfirst()
For Index = 1 To 8
Edsid3(index) = Dsid3(index)
Next Index
If Dsid3(8) = Crc8(dsid3(1) , 7) Then
Locate 1 , 1
Lcd "OK - Czujnik ID"
Wait 1
Locate 2 , 1
For B = 1 To 8
Lcd Hex(dsid3(b))
Next
End If
Wait 1
Return
Irq_timer1:
Tri1 = 1
Stop Timer1
Return
Zero:
Tri1 = 0
Table = Lookup(moc , Tablica)
Load Timer1 , Table
Start Timer1
Return
Tablica:
Data 0%
Data 800% , 760% , 620% , 470% , 10%