' Oster-Contest, Nimm (68%)
'
' Die Anzahl der Hölzchen wird binär an LED 1-5 angezeigt, 2^1, 2^2, usw.
' halb-helle Anzeige binär (Zeile 46 heller<->dunkler)
' Der Mensch beginnt und gibt über die Tasten 1..5 Hölzchen ein.
' helle Anzeige der Taste
' Der Tiny13 zeigt seine Wahl über eine LED 1..5 an.
' helle Anzeige des Tiny13, mehr als 1 Hölzchen übrig -> nochmal
'
' blinkt die '5' hat der Tiny13 gewonnen
' blinkt die '1' hat der Mensch gewonnen
' eine falsche Eingabe wird ignoriert
'-------------------------------------------------------------------------------
' ___ rot / ___
' |-|___|-+--|<|--o--o o--+-|___|-o +3V-5V
' 120 | L0 PB0 S0 | 120
' | rot / |
' +--|<|--o--o o--+
' | L1 PB1 S1 |
' | rot / |
' +--|<|--o--o o--+
' | L2 PB2 S2 |
' | rot / |
' +--|<|--o--o o--+
' | L3 PB3 S3 |
' | rot / |
' +--|<|--o--o o--+
' L4 PB4 S4
'
' alle LED haben einen Schutzwiderstand nach GND
' alle Tasten haben einen Schutzwiderstand nach +Ubatt
' alle Tasten und LED sind an der Anzapfung mit den Ports verbunden
'-------------------------------------------------------------------------------
' $PROG &HFF,&H6A,&HFF,&H00, alle Fuse-Byte ab Werk
'-------------------------------------------------------------------------------
$regfile = "attiny13.dat"
$crystal = 1200000 ' 9,6MHz/8
$hwstack = 8
Dim State As Byte
Dim Zug As Byte 'Tipp: mit 5 beginnen
Do 'Hauptprogramm
State = 30 '30 Hölzchen
Main: 'warte auf zug
Ddrb = 31 'Ausgang
Portb = State 'zeig binär
Waitus 1 'Halb-hell
Portb = 0 'Anzeige dunkel
Ddrb = 0 'Eingang
Zug = Pinb 'Taste?
Ddrb = 31 'Ausgang
If Zug <> 0 Then : Portb = Zug : Waitms 999 : End If 'zeig Taste
If Zug = 1 Then Goto Main1 'Taste 1
If Zug = 2 Then Goto Main1 'Taste 2
If Zug = 4 Then : Zug = 3 : Goto Main1 : End If 'Taste 3
If Zug = 8 Then : Zug = 4 : Goto Main1 : End If 'Taste 4
If Zug = 16 Then : Zug = 5 : Goto Main1 : End If 'Taste 5
Goto Main 'keine Taste
Main1:
If Zug > State Then Goto Main 'falsche Eingabe
State = State - Zug 'zeig Zug Mensch
Portb = 0 : Waitms 666 'Pause
If State > 25 Then Zug = State - 25 'gewinnt
If State = 25 Then Zug = 5 'Verliererstrasse
If State < 25 Then
If State > 19 Then Zug = State - 19 'gewinnt
End If
If State = 19 Then Zug = 3 'Verliererstrasse
If State < 19 Then
If State > 13 Then Zug = State - 13 'gewinnt
End If
If State = 13 Then Zug = 4 'Verliererstrasse
If State < 13 Then
If State > 7 Then Zug = State - 7 'gewinnt
End If
If State = 7 Then Zug = 2 'Verliererstrasse
If State < 7 Then
If State > 1 Then Zug = State - 1 'gewinnt
End If
If State = 1 Then Goto Verloren 'tiny13 hat verloren
If State = 0 Then Goto Gewonnen 'Mensch hat verloren
State = State - Zug
If Zug = 5 Then Zug = 16
If Zug = 4 Then Zug = 8
If Zug = 3 Then Zug = 4
Portb = Zug : Waitms 999 'zeige Tiny13-Zug
Goto Main 'nochmal
Gewonnen:
Zug = 16 'Tiny13 hat gewonnen
Goto Main8
Verloren:
Zug = 1 'Mensch hat gewonnen
Main8:
For State = 1 To 12
Portb = Zug : Waitms 333 : Portb = 0 : Waitms 333 'blink
Next
Loop 'nochmal
' End Program