Hallo,
kann mir jemand erklären warum der folgende Code funktioniert:
Code:
$regfile = "m8def.dat"
$crystal = 3686400
$baud = 9600
$lib "mcsbyte.lbx"
Config Rc5 = Pinc.5
Enable Interrupts
Dim Zaehler As Byte
Dim Address As Byte , Command As Byte
Dim I As Byte
Dim Led1 As Byte
Dim Led2 As Byte
Dim Led3 As Byte
Dim D1 As Byte
Dim D2 As Byte
Dim D3 As Byte
Dim D4 As Byte
Dim D5 As Byte
Dim D6 As Byte
Dim D2_1 As Byte
Dim D4_1 As Byte
Dim D6_1 As Byte
Zaehler = 0
Do
Getrc5(address , Command)
If Command = 16 Then
Zaehler = Zaehler + 1
Elseif Command = 144 Then
Zaehler = Zaehler + 1
Elseif Command = 17 Then
Zaehler = Zaehler - 1
Elseif Command = 145 Then
Zaehler = Zaehler - 1
End If
Print Zaehler ; " " ; Led1 ; " " ; Led2 ; " " ; Led3
D1 = Zaehler 'aktueller Zählwert
D2_1 = Zaehler - 40 '40 subtrahieren, weil in 6er-Schritten bis 240
D2 = Not D2_1 'Wert invertieren -> LED wird dunkler
D3 = Zaehler - 80
D4_1 = Zaehler - 120
D4 = Not D4_1
D5 = Zaehler - 160
D6_1 = Zaehler - 200
D6 = Not D6_1
If Zaehler <= 40 Then
Led1 = 240
Led2 = D1 * 6
Led3 = 0
Else
If Zaehler <= 80 Then
Led1 = D2 * 6
Led2 = 240
Led3 = 0
Else
If Zaehler <= 120 Then
Led1 = 0
Led2 = 240
Led3 = D3 * 6
Else
If Zaehler <= 160 Then
Led1 = 0
Led2 = D4 * 6
Led3 = 240
Else
If Zaehler <= 200 Then
Led1 = D5 * 6
Led2 = 0
Led3 = 240
Else
If Zaehler <= 240 Then
Led1 = 240
Led2 = 0
Led3 = D6 * 6
Else
If Zaehler > 240 Then 'Restwert von 15 (255-240) "abschneiden"
Led1 = 240
Led2 = 0
Led3 = 0 'LED bleibt dunkel
End If
End If
End If
End If
End If
End If
End If
Loop
End
dieser hier nach Einbau eines Timers aber nicht mehr:
Code:
$regfile = "m8def.dat"
$crystal = 3686400
$lib "mcsbyte.lbx"
Config Rc5 = Pinc.5
$baud = 9600
Ddrd = &B11111111
Ddrb = &B11111111
Config Timer0 = Timer , Prescale = 8
On Timer0 Timer_irq
Enable Timer0
Enable Interrupts
Dim Zaehler As Byte
Dim Address As Byte , Command As Byte
Dim I As Byte
Dim Led1 As Byte
Dim Led2 As Byte
Dim Led3 As Byte
Dim D1 As Byte
Dim D2 As Byte
Dim D3 As Byte
Dim D4 As Byte
Dim D5 As Byte
Dim D6 As Byte
Dim D2_1 As Byte
Dim D4_1 As Byte
Dim D6_1 As Byte
Zaehler = 0
Do
'Hauptschleife
Getrc5(address , Command)
If Command = 16 Then
Zaehler = Zaehler + 1
Elseif Command = 144 Then
Zaehler = Zaehler + 1
Elseif Command = 17 Then
Zaehler = Zaehler - 1
Elseif Command = 145 Then
Zaehler = Zaehler - 1
End If
Print Zaehler ; " " ; Led1 ; " " ; Led2 ; " " ; Led3
D1 = Zaehler 'aktueller Zählwert
D2_1 = Zaehler - 40 '40 subtrahieren, weil in 6er-Schritten bis 240
D2 = Not D2_1 'Wert invertieren -> LED wird dunkler
D3 = Zaehler - 80
D4_1 = Zaehler - 120
D4 = Not D4_1
D5 = Zaehler - 160
D6_1 = Zaehler - 200
D6 = Not D6_1
If Zaehler <= 40 Then
Led1 = 240
Led2 = D1 * 6
Led3 = 0
Else
If Zaehler <= 80 Then
Led1 = D2 * 6
Led2 = 240
Led3 = 0
Else
If Zaehler <= 120 Then
Led1 = 0
Led2 = 240
Led3 = D3 * 6
Else
If Zaehler <= 160 Then
Led1 = 0
Led2 = D4 * 6
Led3 = 240
Else
If Zaehler <= 200 Then
Led1 = D5 * 6
Led2 = 0
Led3 = 240
Else
If Zaehler <= 240 Then
Led1 = 240
Led2 = 0
Led3 = D6 * 6
Else
If Zaehler > 240 Then 'Restwert von 15 (255-240) "abschneiden"
Led1 = 240
Led2 = 0
Led3 = 0 'LED bleibt dunkel
End If
End If
End If
End If
End If
End If
End If
Loop
Timer_irq: 'Timer-Interrupt
Timer0 = 237
I = I + 1
If I = 240 Then
I = 0
End If
If I >= Led1 Then
Portd.0 = 0
Portd.1 = 0
Portd.2 = 0
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
End If
If I < Led1 Then
Portd.0 = 1
Portd.1 = 1
Portd.2 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 1
End If
If I >= Led2 Then
Portd.6 = 0
Portd.7 = 0
Portb.0 = 0
Portb.1 = 0
Portb.2 = 0
Portb.3 = 0
End If
If I < Led2 Then
Portd.6 = 1
Portd.7 = 1
Portb.0 = 1
Portb.1 = 1
Portb.2 = 1
Portb.3 = 1
End If
If I >= Led3 Then
Portb.4 = 0
Portb.5 = 0
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
End If
If I < Led3 Then
Portb.4 = 1
Portb.5 = 1
Portc.0 = 1
Portc.1 = 1
Portc.2 = 1
Portc.3 = 1
End If
Return
End
Mir kommt es momentan vor allen auf die Print-Zeile an. Bei der ersten Code-Variante werden mir im Terminalprogramm permanent die Zählerwerte und die Berechneten Werte (LED) angezeigt.
Ber der zweiten Code-Variante wird mir nur ab und zu mal eine "0" angezeigt.
Woran kann das liegen, ich habe doch eigentlich nur einen Timer eingebaut???
Grüße und Danke
Enrico
Lesezeichen