Witam wszystkich.Skleiłem oto taki kod (Sterowanie czasowo dwoma przekaźnikami).Program działa ale ma jedną wadę z którą nie mogę sobie poradzić:
Pierwszy przekaźnik chcę wyłączyć a drugi załączyć o tej samej godzinie(w tym momencie program wykonuję tylko jedną instrukcję i nie załoncza drugiego przekaźnika.
Oto kod:
Proszę poprawić treść i tytuł wiadomości.
Post raportowany.
[zumek]
Pierwszy przekaźnik chcę wyłączyć a drugi załączyć o tej samej godzinie(w tym momencie program wykonuję tylko jedną instrukcję i nie załoncza drugiego przekaźnika.
Oto kod:
$regfile = "m8def.dat"
$crystal = 8000000
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5
Config Pind.0 = Input 'S1 menu
Config Pind.1 = Input 'S2 +
Config Pind.2 = Input 'S3 -
Config Pind.3 = Input 'S4 esc
Config Portb.0 = Output 'Przekaznik 1
Config Portb.1 = Output 'Przekaznik 2
Config Portb.2 = Output 'Led 1 zasilanie
Config Portb.3 = Output 'Led 2 przekaznik1
Config Portb.4 = Output 'Led 3 przekaznik2
Config Portb.5 = Output 'Podswietlenie LCD
Set Portd.0
Set Portd.1
Set Portd.2
Set Portd.3
S1 Alias Pind.0
S2 Alias Pind.1
S3 Alias Pind.2
S4 Alias Pind.3
Prze1 Alias Portb.0
Prze2 Alias Portb.1
Led1 Alias Portb.2
Led2 Alias Portb.3
Led3 Alias Portb.4
Lcd1 Alias Portb.5
Dim H_wlacz1 As Byte
Dim M_wlacz1 As Byte
Dim S_wlacz1 As Byte
Dim H_wlacz2 As Byte
Dim M_wlacz2 As Byte
Dim S_wlacz2 As Byte
Dim H_wylacz1 As Byte
Dim M_wylacz1 As Byte
Dim S_wylacz1 As Byte
Dim H_wylacz2 As Byte
Dim M_wylacz2 As Byte
Dim S_wylacz2 As Byte
Dim S1 As Bit
Dim S2 As Bit
Dim S3 As Bit
Dim S4 As Bit
Dim Prze1 As Bit
Dim Prze2 As Bit
Dim Led1 As Bit
Dim Led2 As Bit
Dim Led3 As Bit
Config Clock = Soft
Config Date = Dmy , Separator = /
Enable Interrupts
Time$ = "00:00:01"
Date$ = "00/00/00"
Cursor Off
Deflcdchar 1 , 2 , 4 , 32 , 14 , 17 , 17 , 14 , 32
Deflcdchar 2 , 32 , 32 , 14 , 1 , 15 , 17 , 15 , 1
Deflcdchar 3 , 12 , 4 , 6 , 12 , 4 , 4 , 14 , 32
'...............................................................................
Lcd1 = 1
Cls
Lcd "** Sterownik ***"
Lowerline
Lcd "*** czasowy ****"
Wait 3
Cls
Lcd "** Wykonanie ***"
Lowerline
Lcd " Adrian G rski "
Locate 2 , 10
Lcd Chr(1)
Wait 3
'...............................................................................
Glowny:
Do
Cls
Lcd Time$
Locate 1 , 10
Lcd "Czas"
Lowerline
Lcd Date$
Locate 2 , 10
Lcd "Data"
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Ustawwlacz1
End If
End If
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Gosub Podswietlenie1
End If
End If
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
Gosub Podswietlenie2
End If
End If
If H_wlacz1 = _hour Then
If M_wlacz1 = _min Then
If S_wlacz1 = _sec Then
Gosub Wlacz1
End If
End If
End If
If H_wylacz1 = _hour Then
If M_wylacz1 = _min Then
If S_wylacz1 = _sec Then
Gosub Wylacz1
End If
End If
End If
If H_wlacz2 = _hour Then
If M_wlacz2 = _min Then
If S_wlacz2 = _sec Then
Gosub Wlacz2
End If
End If
End If
If H_wylacz2 = _hour Then
If M_wylacz2 = _min Then
If S_wylacz2 = _sec Then
Gosub Wylacz2
End If
End If
End If
Waitms 100
Loop
End
'...............................................................................
Ustawwlacz1:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr H_wlacz1
If H_wlacz1 = 24 Then
H_wlacz1 = 0
End If
End If
End If
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
Incr M_wlacz1
If M_wlacz1 = 60 Then
M_wlacz1 = 0
End If
End If
End If
Locate 1 , 6
Lcd H_wlacz1
Lcd ":"
Lcd M_wlacz1
Lowerline
Lcd " Wlacz przeka.1 "
Waitms 100
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Ustawwylacz1
End If
End If
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Ustawwylacz1:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr H_wylacz1
If H_wylacz1 = 24 Then
H_wylacz1 = 0
End If
End If
End If
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
Incr M_wylacz1
If M_wylacz1 = 60 Then
M_wylacz1 = 0
End If
End If
End If
Locate 1 , 6
Lcd H_wylacz1
Lcd ":"
Lcd M_wylacz1
Lowerline
Lcd "Wylacz przeka.1 "
Waitms 100
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Ustawwlacz2
End If
End If
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Ustawwlacz2:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr H_wlacz2
If H_wlacz2 = 24 Then
H_wlacz2 = 0
End If
End If
End If
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
Incr M_wlacz2
If M_wlacz2 = 60 Then
M_wlacz2 = 0
End If
End If
End If
Locate 1 , 6
Lcd H_wlacz2
Lcd ":"
Lcd M_wlacz2
Lowerline
Lcd " Wlacz przeka.2 "
Waitms 100
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Ustawwylacz2
End If
End If
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Ustawwylacz2:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr H_wylacz2
If H_wylacz2 = 24 Then
H_wylacz2 = 0
End If
End If
End If
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
Incr M_wylacz2
If M_wylacz2 = 60 Then
M_wylacz2 = 0
End If
End If
End If
Locate 1 , 6
Lcd H_wylacz2
Lcd ":"
Lcd M_wylacz2
Lowerline
Lcd "Wylacz przeka.2 "
Waitms 100
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Czas
End If
End If
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Czas:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr _hour
_sec = 0
If _hour = 24 Then
_hour = 0
End If
End If
End If
If S3 = 0 Then
Waitms 25
If S3 = 0 Then
_sec = 0
Incr _min
If _min = 60 Then
_min = 0
End If
End If
End If
Locate 1 , 5
Lcd Time$
Lowerline
Lcd " Ustaw CZAS "
Waitms 100
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Datarok
End If
End If
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Datarok:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr _year
If _year = 99 Then
_year = 0
End If
End If
End If
Locate 1 , 5
Lcd Date$
Locate 1 , 13
Lcd "<"
Locate 1 , 10
Lcd ">"
Lowerline
Lcd " Ustaw ROK "
Waitms 100
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Datamiesiac
End If
End If
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Datamiesiac:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr _month
If _month = 13 Then
_month = 0
End If
End If
End If
Locate 1 , 5
Lcd Date$
Locate 1 , 10
Lcd "<"
Locate 1 , 7
Lcd ">"
Lowerline
Lcd " Ustaw MIESIAC "
Waitms 100
If S1 = 0 Then
Waitms 25
If S1 = 0 Then
Gosub Datadzien
End If
End If
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Datadzien:
Do
Cls
If S2 = 0 Then
Waitms 25
If S2 = 0 Then
Incr _day
If _day = 32 Then
_day = 0
End If
End If
End If
Locate 1 , 5
Lcd Date$
Locate 1 , 7
Lcd "<"
Locate 1 , 4
Lcd ">"
Lowerline
Lcd " Ustaw DZIEN "
Waitms 100
If S4 = 0 Then
Waitms 25
If S4 = 0 Then
Gosub Glowny
End If
End If
Loop
End
'...............................................................................
Wlacz1:
Do
If Prze1 = 1 Then
If Led2 = 1 Then
Gosub Glowny
End If
End If
Cls
Lcd "* Urz dzenie 1 *"
Locate 1 , 6
Lcd Chr(2)
Lowerline
Lcd "*** W czone ***"
Locate 2 , 6
Lcd Chr(3)
Locate 2 , 7
Lcd Chr(2)
Sound Portd.7 , 800 , 700
Prze1 = 1
Led2 = 1
Wait 3
Gosub Glowny
Loop
End
'...............................................................................
Wylacz1:
Do
If Prze1 = 0 Then
If Led2 = 0 Then
Gosub Glowny
End If
End If
Cls
Lcd "* Urz dzenie 1 *"
Locate 1 , 6
Lcd Chr(2)
Lowerline
Lcd "** Wy czone ***"
Locate 2 , 6
Lcd Chr(3)
Locate 2 , 7
Lcd Chr(2)
Sound Portd.7 , 800 , 700
Prze1 = 0
Led2 = 0
Wait 3
Gosub Glowny
Loop
End
'...............................................................................
Wlacz2:
Do
If Prze2 = 1 Then
If Led3 = 1 Then
Gosub Glowny
End If
End If
Cls
Lcd "* Urz dzenie 2 *"
Locate 1 , 6
Lcd Chr(2)
Lowerline
Lcd "*** W czone ***"
Locate 2 , 6
Lcd Chr(3)
Locate 2 , 7
Lcd Chr(2)
Sound Portd.7 , 800 , 700
Prze2 = 1
Led3 = 1
Wait 3
Gosub Glowny
Loop
End
'...............................................................................
Wylacz2:
Do
If Prze2 = 0 Then
If Led3 = 0 Then
Gosub Glowny
End If
End If
Cls
Lcd "* Urz dzenie 2 *"
Locate 1 , 6
Lcd Chr(2)
Lowerline
Lcd "** Wy czone ***"
Locate 2 , 6
Lcd Chr(3)
Locate 2 , 7
Lcd Chr(2)
Sound Portd.7 , 800 , 700
Prze2 = 0
Led3 = 0
Wait 3
Gosub Glowny
Loop
End
'...............................................................................
Podswietlenie1:
Do
Cls
Lcd " Podswietlenie "
Lowerline
Lcd "***** ON *****"
Wait 2
Lcd1 = 1
Gosub Glowny
Loop
End
'...............................................................................
Podswietlenie2:
Do
Cls
Lcd " Podswietlenie "
Lowerline
Lcd "***** OFF ****"
Wait 2
Lcd1 = 0
Gosub Glowny
Loop
End Proszę poprawić treść i tytuł wiadomości.
Post raportowany.
[zumek]