Jak zmienić kod do obsługi 4 przekaźników.
: 28 maja 2020, 6:50
Witam dopiero zaczynam przygodę z Bascom i mam problem chciałbym dodać do tego kodu obsługę ustawiania czasu czy jest możliwość dodania, czy pisać od nowa. Nowy program.
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m16adef.dat" ' specify the used micro ' generated. Take care that the chip supports all fuse bytes.
- $crystal = 8000000
- $baud = 19200
- ' used crystal frequency ' generated. Take care that the chip supports all fuse bytes.
- Config Lcd = 16 * 2
- Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
- Config Pind.0 = Input
- Config Pinc.2 = Output
- Config Pinc.3 = Output
- Config Pinc.4 = Output
- Config Pinc.5 = Output
- Startknop Alias Pind.0
- Relais1 Alias Portc.2
- Relais2 Alias Portc.3
- Relais3 Alias Portc.4
- Relais4 Alias Portc.5
- Dim Compoort As String * 3
- Dim Klaar As Byte
- Dim Minute As Byte
- Dim Second As Byte
- Dim Vanity_once As Bit
- Dim Klepnummer As Byte
- Dim Multiplier As Byte
- Declare Sub Rainmaker(byval Klepnummer As Byte , Byval Minute As Byte)
- Declare Sub Wacht_seconde
- Declare Sub Start_sequence
- Declare Sub Serial_input
- Declare Sub Reset_relays
- Declare Sub Set_zero
- Hier:
- Vanity_once = 1
- Klaar = 1
- Do
- If Vanity_once = 1 Then
- Cls
- Locate 1 , 1 : Lcd "COS TAM" 'Tell the amased spectators what you do
- Locate 2 , 3 : Lcd "COS TAM"
- End If
- Vanity_once = 0
- If Startknop = 0 Then Start_sequence
- Serial_input
- Loop
- Sub Serial_input
- Compoort = Inkey()
- Select Case Compoort
- Case "1"
- Set_zero
- Reset_relays
- Rainmaker 1 , 20
- Case "2"
- Set_zero
- Reset_relays
- Rainmaker 2 , 20
- Case "3"
- Set_zero
- Reset_relays
- Rainmaker 3 , 20
- Case "4"
- Set_zero
- Reset_relays
- Rainmaker 4 , 20
- Case "5"
- Start_sequence
- Case "6"
- Goto Gestopt
- End Select
- End Sub
- Sub Start_sequence
- Rainmaker 1 , 1 'open valve 1 for 20 minutes
- Rainmaker 2 , 1 'open valve 2 ...
- Rainmaker 3 , 1 'and so on
- Rainmaker 4 , 1
- End Sub
- Sub Rainmaker(byval Klepnummer As Byte , Byval Minute As Byte)
- Compoort = ""
- Second = 1
- Cls
- If Klepnummer < 1 Or Klepnummer > 5 Then Goto Gestopt
- If Klepnummer = 1 Then Set Relais1
- If Klepnummer = 2 Then Set Relais2
- If Klepnummer = 3 Then Set Relais3
- If Klepnummer = 4 Then Set Relais4
- Do
- Second = Second - 1
- If Second < 0 Then Goto Gestopt
- Locate 1 , 1 : Lcd "Zawor"
- Locate 1 , 6 : Lcd Klepnummer
- Locate 1 , 8 : Lcd "otwarty"
- Locate 2 , 1 : Lcd "Nadal"
- If Minute > 9 Then Locate 2 , 5 : Lcd Minute
- If Minute < 10 Then
- Locate 2 , 4 : Lcd " "
- Locate 2 , 5 : Lcd "0"
- Locate 2 , 6 : Lcd Minute
- End If
- Locate 2 , 7 : Lcd ":"
- If Second > 9 Then Locate 2 , 8 : Lcd Second
- If Second < 10 Then
- Locate 2 , 8 : Lcd "0"
- Locate 2 , 9 : Lcd Second
- End If
- Locate 2 , 11 : Lcd "Min."
- Klaar = Second + Minute
- If Second = 0 Then Minute = Minute - 1
- If Second = 0 Then Second = 60
- Multiplier = 100
- Do
- Decr Multiplier
- Waitus 9550 '100 x 10000us = 1 second <-- this number makes 1 sec
- Loop Until Multiplier = 0
- Serial_input
- If Startknop = 0 Then Goto Gestopt 'stop op nogmaals startknop drukken
- Loop Until Klaar = 0
- Reset_relays
- Vanity_once = 1
- End Sub
- Gestopt:
- Cls
- Set_zero
- Reset_relays
- Locate 1 , 5 : Lcd "STOP!"
- Wait 3
- Goto Hier
- Sub Reset_relays
- Reset Relais1
- Reset Relais2
- Reset Relais3
- Reset Relais4
- End Sub
- Sub Set_zero
- Compoort = "0"
- Klepnummer = 0
- Second = 0
- Minute = 0
- Klaar = 0
- End Sub