Eine Idee:
Code:
$regfile = "m8def.dat"
$crystal = 1000000
Config Timer0 = Timer , Prescale = 1024 'längster Impuls (bei 1 MHZ etwa 1/4 Sekunde) für längere Zeit 16 Bit Timer nehmen
On Timer0 Timer_irq
Enable Timer0
Enable Interrupts
Ddrc = &B00001111 'Ausgänge an Port C0-3
Ddrb = 0 'Eingänge an B0-3
Dim Pinb_alt As Byte
Do
Loop
End
Timer_irq:
Dim I As Byte
For I = 0 To 3
If Pinb_alt.i <> Pinb.i Then
Set Portc.i
Else
Reset Portc.i
End If
Next I
Pinb_alt = Pinb
Return
Oder für längeren Impuls:
Code:
$regfile = "m8def.dat"
$crystal = 1000000
Const Impulsdauer = 5 '4fache Impulsdauer
Config Timer0 = Timer , Prescale = 1024 'längster Impuls (bei 1 MHZ etwa 1/4 Sekunde) für längere Zeit 16 Bit Timer nehmen
On Timer0 Timer_irq
Enable Timer0
Enable Interrupts
Ddrc = &B00001111 'Ausgänge an Port C0-3
Ddrb = 0 'Eingänge an B0-3
Dim Pinb_alt As Byte
Dim Zeit(4) As Byte
Dim I As Byte
Do
If Zeit(4) >= 1 Then '>=1 erzeugt kleineren Code als >0...
For I = 0 To 3
If Zeit(i) >= 1 Then
Decr Zeit(i)
End If
If Zeit(i) = 0 Then
Reset Portc.i
Else
Set Portc.i
End If
If Pinb_alt.i <> Pinb.i Then
Zeit(i) = Impulsdauer
End If
Next I
Pinb_alt = Pinb
Zeit(4) = 0
End If
Loop
End
Timer_irq:
Incr Zeit(4)
Return
Lesezeichen