Hallo,
ich habe nen an einem mega8 über einen ULN2803 zwei Relais hängen. Über die RS485 Schnittstelle sende ich Befehle, um die Relais anziehen zu lassen. Zusätzlich habe ich eine per Software eine "Verriegelung" eingebaut, damit nie die zwei Relais gleichzeitig anziehen können. Das funktioniert auch alles prima. Jetzt soll, wenn der Befehl zum schalten des Relais1 kommt, das Relais anziehen und nach 10 sekunden wieder abfallen.
Folgender Code funzt ( ohne Timer ) :
Nur wie stelle ich es an, das die Relais nach 10 Sekunden wieder abfallen ?Code:'--------------------------------- Chip Definiton ---------------------------- $regfile = "m8def.dat" $crystal = 16000000 $baud = 1200 '--------------------------------- Portdefinition ---------------------------- Config Portb = Output Config Portd = Output Config Portc = Output '----------------------------------------- Timer ------------------------------ '------------------------------------------ Subs ----------------------------- Declare Sub Blinken Declare Sub Rolloauf Declare Sub Rolloab Declare Sub Rolloaufcheck Declare Sub Rolloabcheck Declare Sub Hochzehlen '-------------------------------------- Dims -------------------------------- Dim I As Byte Dim Temp1 As Byte Dim Adresse As Byte Dim Funktion As Byte 'Dim Myadress As Byte Dim Stoppbyte As Byte Dim X As Byte Dim Rauf As Bit Dim Rab As Bit Dim Uauf As Bit Dim Uab As Bit '-------------------------------- Aliasse ------------------------------------ Auf Alias Portc.4 Ab Alias Portc.5 Rs485 Alias Portd.2 Led Alias Portb.1 '------------------------------------------ Syncbytes ------------------------ Const Sync = &B01010100 Const Myadress = &H02 '------------------------------------ Call Blinken ------------------------------ Call Blinken Auf = 0 Ab = 0 Rauf = 0 Rab = 0 Ueberlauf = 0 '------------------------------------ Hauptroutine -------------------------- _start: Temp1 = Waitkey() If Temp1 <> Sync Then Goto _start Else Inputbin Adresse , Funktion , Stoppbyte If Adresse <> Myadress Then Goto _start If Funktion = &H01 Then Goto Rolloauf If Funktion = &H02 Then Goto Rolloab If Stoppbyte = &H7F Then Goto _start End If '--------------------------------------- Rolloauf ----------------------------- Rolloauf: Led = 1 Waitms 100 Led = 0 If Rab = 1 Then Goto _start Else Toggle Auf : Toggle Rauf End If Goto Rolloaufcheck '--------------------------------------- Rolloaufcheck ---------------------- Rolloaufcheck: Goto _start '------------------------------------- Rolloab ------------------------------- Rolloab: Led = 1 Waitms 100 Led = 0 If Rauf = 1 Then Goto _start Else Toggle Ab : Toggle Rab End If Goto Rolloabcheck '----------------------------------- Rolloabcheck ------------------------ Rolloabcheck: Goto _start '------------------------------------------ Hochzehlen ------------------- Hochzehlen: Return '-------------------------------- Blinken -------------------------------------- Blinken: Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Return
Ich habe versucht, durch den Timer1 ne Variable hochzählen zu lassen, aber das hat nicht geklappt.
Hab es so probiert :
Wie könnte ich das denn richtig lösen ? vielen dankCode:'--------------------------------- Chip Definiton ---------------------------- $regfile = "m8def.dat" $crystal = 16000000 $baud = 1200 '--------------------------------- Portdefinition ---------------------------- Config Portb = Output Config Portd = Output Config Portc = Output '----------------------------------------- Timer ------------------------------ Config Timer1 = Timer , Prescale = 256 Enable Interrupts Enable Timer1 On Timer1 Hochzaehlen '------------------------------------------ Subs ----------------------------- Declare Sub Blinken Declare Sub Rolloauf Declare Sub Rolloab Declare Sub Rolloaufcheck Declare Sub Rolloabcheck Declare Sub Hochzaehlen '-------------------------------------- Dims -------------------------------- Dim I As Byte Dim Temp1 As Byte Dim Adresse As Byte Dim Funktion As Byte 'Dim Myadress As Byte Dim Stoppbyte As Byte Dim X As Byte Dim Rauf As Bit Dim Rab As Bit Dim Uauf As Bit Dim Uab As Bit Dim Timerwert As Byte '-------------------------------- Aliasse ------------------------------------ Auf Alias Portc.4 Ab Alias Portc.5 Rs485 Alias Portd.2 Led Alias Portb.1 '------------------------------------------ Syncbytes ------------------------ Const Sync = &B01010100 Const Myadress = &H02 '------------------------------------ Call Blinken ------------------------------ Call Blinken Auf = 0 Ab = 0 Rauf = 0 Rab = 0 Timerwert = 0 '------------------------------------ Hauptroutine -------------------------- _start: Temp1 = Waitkey() If Temp1 <> Sync Then Goto _start Else Inputbin Adresse , Funktion , Stoppbyte If Adresse <> Myadress Then Goto _start If Funktion = &H01 Then Goto Rolloauf If Funktion = &H02 Then Goto Rolloab If Stoppbyte = &H7F Then Goto _start End If '--------------------------------------- Rolloauf ----------------------------- Rolloauf: Led = 1 Waitms 100 Led = 0 If Rab = 1 Then Goto _start Else Toggle Auf : Toggle Rauf : Timerwert = 0 : Start Timer1 End If Goto Rolloaufcheck '--------------------------------------- Rolloaufcheck ---------------------- Rolloaufcheck: Goto _start '------------------------------------- Rolloab ------------------------------- Rolloab: Led = 1 Waitms 100 Led = 0 If Rauf = 1 Then Goto _start Else Toggle Ab : Toggle Rab : Timerwert = 0 : Start Timer1 End If Goto Rolloabcheck '----------------------------------- Rolloabcheck ------------------------ Rolloabcheck: Goto _start '------------------------------------------ Hochzehlen ------------------- Hochzaehlen: Timerwert = Timerwert + 1 If Timerwert = 10 Then Ab = 0 : Toggle Rab If Timerwert = 11 Then Auf = 0 : Toggle Rauf Return '-------------------------------- Blinken -------------------------------------- Blinken: Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Portb.1 = 1 Waitms 100 Portb.1 = 0 Waitms 100 Return
mfg Kay







Zitieren

Lesezeichen