Das sollte eine Lösung sein:
Code:
$crystal = 1000000
Disable Interrupts
$regfile = "m16def.dat" 'Atmega 16
$hwstack = 40
$swstack = 40
$framesize = 60
Config Portd.4 = Output 'Ausgang
Config Pind.5 = Input 'Taste 1
Config Pind.6 = Input 'Taste 2
Config Pind.7 = Input 'Zündung
Ausgang Alias Portd.4
Taste1 Alias Pind.5
Taste2 Alias Pind.6
Zundung Alias Pind.7
Portd.5 = 1 'Pullups, sodass Taster nur auf GND ziehen brauchen
Portd.6 = 1
Portd.7 = 0 'Zündung per Pulldown auf GND ziehen und mittel Optokoppler auf High, wenn Zündung an
Dim Code As Byte
Dim Tickcount As Long 'Lauzeit in 10 mSek Schritten
Config Timer0 = Timer , Prescale = 64 '1 mhz
On Timer0 Timer_irq
Const Timervorgabe = 100 '1 mhz
Enable Timer0
Enable Interrupts
Do
If Zundung = 0 Then
Code = 0
Tickcount = 0
Else
If Tickcount < 500 Then '5 Sekunden
If Code = 0 And Taste1 = 0 And Taste2 = 1 Then Code = 1 'Taste 1 gedrückt
If Code = 0 And Taste1 = 1 And Taste2 = 0 Then Tickcount = 500 'falscher Code
If Code = 1 And Taste1 = 1 And Taste2 = 1 Then Code = 2 'keine Taste gedrückt
If Code = 2 And Taste1 = 1 And Taste2 = 0 Then Code = 3 'Taste 2 gedrückt
If Code = 2 And Taste1 = 0 And Taste2 = 1 Then Tickcount = 500 'falscher Code
If Code = 3 And Taste1 = 1 And Taste2 = 1 Then Code = 4 'keine Taste gedrückt
If Code = 4 And Taste1 = 1 And Taste2 = 0 Then Code = 5 'Taste 2 gedrückt
If Code = 4 And Taste1 = 0 And Taste2 = 1 Then Tickcount = 500 'falscher Code
If Code = 5 And Taste1 = 1 And Taste2 = 1 Then Code = 6 'keine Taste gedrückt
End If
End If
If Zundung = 0 Or Code = 6 Then
Set Ausgang
Else
Reset Ausgang
End If
Loop
End
Timer_irq:
Timer0 = Timervorgabe
Tickcount = Tickcount + 1
If Tickcount = 2147483647 Then Tickcount = 0 'sollte es eigentlich nie zu kommen
Return
Lesezeichen