2.es Programm mit Simulationstest erfolgreich
Ui, mein erster Code hatte doch viele Fehler. Jetzt habe ich sogar das mit dem Interrupt verbessert und im Simulator funktioniert bisher alles tadellos.
Code:
$regfile = "m32def.dat"
$crystal = 1000000
'***********************************************************************'
Dim Scheibe As Integer
Dim Punkte As Integer
Dim Scheibe_akt As Bit
Dim A As Byte
Dim B As Byte
A = 0
B = 0
Scheibe = 2
Punkte = 0
Config Portd.0 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Int0 = Rising
Config Int1 = Rising
Enable Interrupts
Enable Int0
Enable Int1
On Int0 Int0_5punkte
On Int1 Int1_10punkte
Do
'---------------------'
If Scheibe = 1 Then
Portd.0 = 1
Scheibe = 0
Do
Incr Scheibe
Waitms 250
If Scheibe_akt = 1 Then
Goto Anfang
End If
Incr B
If Scheibe = 3 Then
Scheibe = 0
End If
Loop Until B = 8
Scheibe = 2
Goto Anfang
Else
Portd.0 = 0
End If
'---------------------'
If Scheibe = 2 Then
Portd.5 = 0
Scheibe = 0
Do
Incr Scheibe
Waitms 250
If Scheibe_akt = 1 Then
Goto Anfang
End If
Incr B
If Scheibe = 3 Then
Scheibe = 0
End If
Loop Until B = 8
Scheibe = 3
Goto Anfang
Else
Portd.5 = 0
End If
'---------------------'
If Scheibe = 3 Then
Portd.6 = 1
Scheibe = 0
Do
Incr Scheibe
Waitms 250
If Scheibe_akt = 1 Then
Goto Anfang
End If
Incr B
If Scheibe = 3 Then
Scheibe = 0
End If
Loop Until B = 8
Scheibe = 1
Goto Anfang
Else
Portd.6 = 0
End If
Anfang:
Scheibe_akt = 0
B = 0
Waitms 1000
Incr A
Loop Until A = 20
End 'hier erscheint ein Ton und zeigt das Ende mit Ergebnis.
'*************************************************************************'
Int0_5punkte:
Punkte = Punkte + 5
Portd.0 = 0
Portd.5 = 0
Portd.6 = 0
Scheibe_akt = 1
Return
Int1_10punkte:
Punkte = Punkte + 10
Portd.0 = 0
Portd.5 = 0
Portd.6 = 0
Scheibe_akt = 1
Return
3. Programm mit Hardware getestet und Fehler behoben
Moin,
Nun funktioniert alles super. Der Zufall ist sogar viel besser mit 50ms.
Ich wollte dies jetzt nur für mich vollenden, damit ich auch mal eins hin bekomme :) Und nun muss ich mich mal mit den ATmega88 beschäftigen, was der so alles braucht.
Wenn ich das ATmega88 habe, kann ich die einzelnen Trigger deaktiveren, um ein 2. Treffer zu verhinden?
-EDIT-
Ich habe eben bemergt, das ich schon bei 3kb bin und ich werde bestimmt über 8kb kommen, und von daher lohnt sich der atmega88 leider nicht. Kennt jemand noch einen der mindestens 6 Triggers umschalten kann?
mfg EKI
Hier der Code, und sogar noch optimiert:
Code:
$regfile = "m32def.dat"
$framesize = 32
$swstack = 32
$hwstack = 32
$crystal = 1000000
'***********************************************************************'
Dim Scheibe As Integer
Dim Punkte As Integer
Dim Scheibe_akt As Bit
Dim A As Byte
Dim B As Byte
A = 0
B = 0
Scheibe = 1
Punkte = 0
Config Portd.0 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Int0 = Rising
Config Int1 = Rising
Enable Interrupts
Enable Int0
Enable Int1
On Int0 Int0_5punkte
On Int1 Int1_10punkte
Do
'---------------------'
If Scheibe = 1 Then
Portd.0 = 1
Scheibe = 0
Do
Incr Scheibe
Waitms 50
If Scheibe_akt = 1 Then
Goto Anfang
End If
Incr B
If Scheibe = 3 Then
Scheibe = 0
End If
Loop Until B = 15
Scheibe = 2
Portd.0 = 0
Goto Anfang
Else
Portd.0 = 0
End If
'---------------------'
If Scheibe = 2 Then
Portd.5 = 1
Scheibe = 0
Do
Incr Scheibe
Waitms 50
If Scheibe_akt = 1 Then
Goto Anfang
End If
Incr B
If Scheibe = 3 Then
Scheibe = 0
End If
Loop Until B = 15
Scheibe = 3
Portd.5 = 0
Goto Anfang
Else
Portd.5 = 0
End If
'---------------------'
If Scheibe = 3 Then
Portd.6 = 1
Scheibe = 0
Do
Incr Scheibe
Waitms 50
If Scheibe_akt = 1 Then
Goto Anfang
End If
Incr B
If Scheibe = 3 Then
Scheibe = 0
End If
Loop Until B = 15
Scheibe = 1
Portd.6 = 0
Goto Anfang
Else
Portd.6 = 0
End If
Anfang:
Scheibe_akt = 0
B = 0
Waitms 2000
Incr A
Loop Until A = 20
Portd.0 = 1
Portd.5 = 1
Portd.6 = 1
End 'hier erscheint ein Ton und zeigt das Ende mit Ergebnis.
'*************************************************************************'
Int0_5punkte:
Punkte = Punkte + 5
Portd.0 = 0
Portd.5 = 0
Portd.6 = 0
Scheibe_akt = 1
Return
Int1_10punkte:
Punkte = Punkte + 10
Portd.0 = 0
Portd.5 = 0
Portd.6 = 0
Scheibe_akt = 1
Return
Liste der Anhänge anzeigen (Anzahl: 1)
Ich hab nochmal darüber nachgedacht, wie man etwas sparsamer mit den I/O-Ports umgehen könnte. Herausgekommen ist eine Lösung, die mit zwei Interrupt-Eingängen auskommt, und weitere 6 Ports die Aktivierung der einzelnen Scheiben übernehmen, und zwar sowohl der Taster als auch der LEDs, die bei der aktiven Scheibe ja leuchten sollen.
Zur Funktion: Die beiden Interrupt-Eingänge sind über die internen PullUp-Widerstände auf 1 gelegt und müssen folglich als "falling" konfiguriert werden. Die Taster jeder einzelnen Scheibe gehen dann auf einen I/O-Port. Liegt an diesem Port ein High, sind die Taster wirkungslos, weil sie den Interrupt-Eingang somit nicht auf Low ziehen können. Einer der 6 I/O-Ports ist also immer auf Low, und nur die daran angeschlossenen Taster können den Interrupt auslösen.
Als "Abfallprodukt" kann man mit diesem Low-Pegel dann über einen PNP-Transistor auch gleich die LEDs einschalten. Für 6 LEDs (so sah ja Deine Zeichnung aus) brauchst Du sowieso pro Scheibe einen Transistor, denn soviel Strom kann ein normaler Port nicht liefern.
Das hieße also, dass Du für die komplette Steuerung und Abfrage der Scheiben lediglich die beiden Interrupts + 6 I/O-Ports bräuchtest. Und somit käme der Mega8 wieder in Frage :-)
Anhang 24506