-
Zufallsgenerator
Bin vor paar tagen angefangen mich bissl in µC einzu arbeiten habe ne kleine anzeige mit einer 7 Segment programmiert der dauerhaft nacheinander ne zufällige Zahl anzeigt.
Mein Code ist aber ziemlich lang wollte mal fragen ob ihr tipps für mich habt den code bissl kleiner zu bekommen
Code:
$regfile = "m8def.dat"
$framesize = 32
$swstack = 32
$hwstack = 32
$crystal = 16000000
$baud = 9600
Config Portc.5 = Output
Config Portc.4 = Output
Config Portc.3 = Output
Config Portc.2 = Output
Config Portc.1 = Output
Config Portc.0 = Output
Config Portb.5 = Output
Config Portb.4 = Output
1a Alias Portb.4
2a Alias Portb.5
4a Alias Portc.0
5a Alias Portc.1
6a Alias Portc.5
7a Alias Portc.4
9a Alias Portc.3
10a Alias Portc.2
Dim I As Word
Do
I = Rnd(10)
If I = 0 Then
1a = 0
2a = 1
4a = 1
5a = 1
6a = 0
7a = 1
9a = 1
10a = 1
Waitms 50
End If
If I = 1 Then
1a = 0
2a = 0
4a = 0
5a = 1
6a = 0
7a = 1
9a = 0
10a = 0
Waitms 50
End If
If I = 2 Then
1a = 1
2a = 0
4a = 1
5a = 1
6a = 0
7a = 0
9a = 1
10a = 1
Waitms 50
End If
If I = 3 Then
1a = 1
2a = 0
4a = 1
5a = 1
6a = 0
7a = 1
9a = 1
10a = 0
Waitms 50
End If
If I = 4 Then
1a = 1
2a = 1
4a = 0
5a = 1
6a = 0
7a = 1
9a = 0
10a = 0
Waitms 50
End If
If I = 5 Then
1a = 1
2a = 1
4a = 1
5a = 0
6a = 0
7a = 1
9a = 1
10a = 0
Waitms 50
End If
If I = 6 Then
1a = 1
2a = 1
4a = 1
5a = 0
6a = 0
7a = 1
9a = 1
10a = 1
Waitms 50
End If
If I = 7 Then
1a = 0
2a = 0
4a = 1
5a = 1
6a = 0
7a = 1
9a = 0
10a = 0
Waitms 50
End If
If I = 8 Then
1a = 1
2a = 1
4a = 1
5a = 1
6a = 0
7a = 1
9a = 1
10a = 1
Waitms 50
End If
If I = 9 Then
1a = 1
2a = 1
4a = 1
5a = 1
6a = 0
7a = 1
9a = 1
10a = 0
Waitms 50
End If
Loop
End
-
Du könntest es mit 'Case' etwas komprimieren.
Gruß
zebrafalke
-
was für einen treiber-ic könte ich für solch einfache schaltungen verwenden?
edit: hast für case nen kleines beispiel?
-
In der Bascom Hilfe steht ein Beispiel:
Code:
Dim I As Byte 'dim variable
Dim S As String * 5 , Z As String * 5
Do
Input "Enter value (0-255) " , I
Select Case I
Case 1 : Print "1"
Case 2 : Print "2"
Case 3 To 5 : Print "3-5"
Case Is >= 10 : Print ">= 10"
Case Else : Print "Not in Case statement"
End Select
Loop
Guck dir das mal an, die Hilfe ist sowieso sehr praktisch finde ich.