PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Interuptsteuerung bei RS485



elkokiller
25.10.2006, 08:30
Hallo,

ich habe den angehängten Code zur Fernsteuerung von 5 Relais geschrieben.
Es funktioniert auch soweit bis auf die Fernsteuerung.
Bei Eingabe von t1-1 zieht verändert das erste Relai seinen Schaltzustand bei t1-2 das zweite u.s.w.
Ein Problem bekomme ich nur, wenn ich den Text nicht in dieser Form eingebe oder mich vertippe.
Dann hängt sich die Interruptsteuerung auf.
Was muss ich tun, um den Zustand nach kurzer Zeit, z.b. 1s oder nach Feststellung des Textendes aufzulösen?



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

$regfile = "m8def.dat"
$crystal = 7372800
$baud = 4800


Config Pinc.0 = Input
Config Pinc.1 = Input
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input .
Config Pinc.5 = Input

Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
Config Portd.7 = Output
Config Portd.6 = Output

Config Portb.5 = Output

Config Portd.2 = Output


Dim I As Byte
Dim Key As Byte

Dim S As String * 7
Dim A As String * 4
Dim X1 As Boolean
Dim X2 As Boolean
Dim X3 As Boolean
Dim X4 As Boolean
Dim Z As String * 1
Dim W As String * 1


' **** Timer *********************************************

Dim T1 As Long
Dim T2 As Long
Dim T3 As Long
Dim T4 As Long
Dim T5 As Long


Dim R1 As Bit
Dim R2 As Bit
Dim R3 As Bit
Dim R4 As Bit
Dim R5 As Bit


Const Keys = 5

' **** Programmstart **************************************

Do


R1 = Portb.0
R2 = Portb.1
R3 = Portb.2
R4 = Portd.6
R5 = Portd.7



' **** RS485 Aktivieren und Bus prüfen

On Urxc Onrxd
Enable Urxc
Enable Interrupts


If Len(s) > 3 Then
A = S
S = ""
Goto Pruefung 'Text ist größer als 3 Stellen


Else

'Disable Interrupts
'Disable Urxc
End If


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

Portb.5 = 1

For I = 1 To Keys
Key = I
Select Case Key
Case 1 : Debounce Pinc.0 , 0 , Key_o1 , Sub 'Port 1.
Case 2 : Debounce Pinc.1 , 0 , Key_o2 , Sub 'Port 2
Case 3 : Debounce Pinc.2 , 0 , Key_o3 , Sub 'Port 3
Case 4 : Debounce Pinc.3 , 0 , Key_o4 , Sub 'Port 4
Case 5 : Debounce Pinc.4 , 0 , Key_o5 , Sub 'Port 5


End Select
Next

Loop

Key_o1:
Toggle Portb.0 'Buchse 1
Return


Key_o2:
Toggle Portb.1 'Buchse 2
Return


Key_o3:
Toggle Portb.2 'Buchse 3
Return


Key_o5:
Toggle Portd.6 'Buchse 4
Return

Key_o4:
Toggle Portd.7 'Buchse 5
Return




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


Onrxd:
S = S + Chr(udr)
Return

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


Pruefung: 'Prüfung ob t1 in den ersten beiden Stellen enthalten ist

Z = Mid(a , 1 , 2 )
If Z = "t1" Then
Goto Fern
A = Mid(s , 1 , 6)
Else

S = ""

Disable Interrupts
Disable Urxc
End If

Return

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

Fern:
Disable Interrupts

W = Mid(a , 4 , 1 )
If W = "1" Then Gosub Key_o1
If W = "2" Then Gosub Key_o2
If W = "3" Then Gosub Key_o3
If W = "4" Then Gosub Key_o4
If W = "5" Then Gosub Key_o5

Disable Urxc
Waitms 100
Portd.2 = 1

Waitms 10
Print

Print "$t1-" ; R3 ; R2 ; R1 ; R5 ; R4


Waitms 100
Portd.2 = 0

Return


End

elkokiller
27.10.2006, 17:14
Kann mir keiner helfen?

PicNick
27.10.2006, 17:40
*murmel*
Also, der korrekte Input wäre "$T1-", bzw "$T2-" etc ?
Und wenn, dann wird 1, 2 etc. getoggelt ?

elkokiller
27.10.2006, 19:56
nein, Input ist "t1-1", "t1-2", etc.
wie gesagt, es geht auch bis ich mich vertippe...

Die Bestätigung, dass etwas geschaltet hat, lautet dann "$t1-00001"

Kannst du damit etwas anfangen?