Hallo
Ein paar Anmerkungen:
Code:
Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Portb.0 = Output
Config Pinc.5 = Input
Config Pinc.4 = Input
Config Pinc.3 = Input
Config Pinc.2 = Input
Config Pinc.1 = Input
Config Pinc.0 = Input
Config Pinb.5 = Input
Config Pinb.4 = Input
Hier die Syntax von Config Port:
Syntax
CONFIG PORTx = state
CONFIG PINx.y = state
Portx bezieht sich auf alle 8 Pins eines Ports, Pinx.y konfiguriert einen einzelnen Pin.
Code:
If Taster8 = 0 Then
Tasternummer = 8
Else
Tasternummer = 0
End If
Wenn Taster8 nicht null ist wird Tastenummer immer auf 0 gesetzt, egal was zuvor erkannt wurde! Besser wäre so:
Code:
Tasteridentifizieren:
'Return <== was soll das hier?
Tasternummer = 0 ' mit 0 vorbelegen
If Taster1 = 0 Then
Tasternummer = 1
End If
...
If Taster8 = 0 Then
Tasternummer = 8
End If
Erstes Element in Arrays hat die Nummer 1!
"The first element of an array is always one by default." (Bascom-Hilfe "Language Fundamentals" -> "Arrays")
Code:
Dim Code(8) As Byte
Codeanzeigen:
Count = 0
While Count < Aktstelle
If Code(count) = 1 Then
...
Codeerstellen:
Count = 0
While Count <= 8
Code(count) = Rnd(7) ' Zufallszahl zwischen 0 und 7 erzeugen und in code(count) speichern
Gruß
mic
(der 5555er :)
[Edit]
ungetestet:
Code:
$regfile = "m8def.dat "
$crystal = 1000000
Config Portd = Output
Config Pinb.0 = Output
Config Pinc.5 = Input
Config Pinc.4 = Input
Config Pinc.3 = Input
Config Pinc.2 = Input
Config Pinc.1 = Input
Config Pinc.0 = Input
Config Pinb.5 = Input
Config Pinb.4 = Input
'Pullups Setzen
Portc.5 = 1
Portc.4 = 1
Portc.3 = 1
Portc.2 = 1
Portc.1 = 1
Portc.0 = 1
Portb.5 = 1
Portb.4 = 1
Taster8 Alias Pinc.5
Taster7 Alias Pinc.4
Taster6 Alias Pinc.3
Taster4 Alias Pinc.2
Taster5 Alias Pinc.1
Taster1 Alias Pinc.0
Taster2 Alias Pinb.5
Taster3 Alias Pinb.4
Ledblau Alias Portb.0
Led6 Alias Portd.0
Led4 Alias Portd.1
Led1 Alias Portd.2
Led7 Alias Portd.3
Led2 Alias Portd.4
Led8 Alias Portd.5
Led5 Alias Portd.6
Led3 Alias Portd.7
'Erzeugter Code
Dim Code(8) As Byte
' Aktuelle Stelle
Dim Aktstelle As Byte
' Verzögerung in ms
Dim Verz As Byte
Dim Count As Byte
Dim Tasternummer As Byte
Verz = 250
Do
For Aktstelle = 1 To 8
Code(aktstelle) = Rnd(7) + 1
Gosub Codeanzeigen
Do
Gosub Tasteridentifizieren
Loop Until Tasternummer = Code(aktstelle)
Next Aktstelle
Gosub Lauflicht
Gosub Lauflicht
Loop
End
Do
If Taster1 = 0 Then
Gosub Codeerstellen
Gosub Lauflicht
Gosub Lauflicht
Gosub Codelesen
End If
Loop
'*******************************************************************************
Codeerstellen:
Count = 0
While Count <= 8
Code(count) = Rnd(7) ' Zufallszahl zwischen 0 und 7 erzeugen und in code(count) speichern
Code(count) = Code(count) + 1
Count = Count + 1
Wend
Return
'*******************************************************************************
Lauflicht:
Led1 = 1
Waitms 100
Led1 = 0
Waitms 100
Led2 = 1
Waitms 100
Led2 = 0
Waitms 100
Led3 = 1
Waitms 100
Led3 = 0
Waitms 100
Led5 = 1
Waitms 100
Led5 = 0
Waitms 100
Led8 = 1
Waitms 100
Led8 = 0
Waitms 100
Led7 = 1
Waitms 100
Led7 = 0
Waitms 100
Led6 = 1
Waitms 100
Led6 = 0
Waitms 100
Led4 = 1
Waitms 100
Led4 = 0
Waitms 100
Return
'*******************************************************************************
Codeanzeigen:
For Count = 1 To Aktstelle
Select Case Code(count)
Case 1 : Led1 = 1
Case 2 : Led2 = 1
Case 3 : Led3 = 1
Case 4 : Led4 = 1
Case 5 : Led5 = 1
Case 6 : Led6 = 1
Case 7 : Led7 = 1
Case 8 : Led8 = 1
End Select
Waitms Verz
Portd = 0 ' alle Led aus
Waitms Verz
Next Count
Return
'*******************************************************************************
Tasteridentifizieren:
Tasternummer = 0
If Taster1 = 0 Then
Tasternummer = 1
End If
If Taster2 = 0 Then
Tasternummer = 2
End If
If Taster3 = 0 Then
Tasternummer = 3
End If
If Taster4 = 0 Then
Tasternummer = 4
End If
If Taster5 = 0 Then
Tasternummer = 5
End If
If Taster6 = 0 Then
Tasternummer = 6
End If
If Taster7 = 0 Then
Tasternummer = 7
End If
If Taster8 = 0 Then
Tasternummer = 8
End If
'*******************************************************************************
Tasteeinlesen:
Led1 = 1
Waitms 800
Gosub Tasteridentifizieren
Waitms 300
Led1 = 0
Return
'*******************************************************************************
Codelesen:
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
If Tasternummer = Code(1) Then
Aktstelle = 2
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
If Tasternummer = Code(2) Then
Aktstelle = 3
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
End If
End If
Return
Lesezeichen