Also pack ich einfach mal in jede ISR und jede Call ein RET(I) rein?
Ich hab grad mein Programm etwas verständlicher geschrieben (kommentiert)
Vielleicht versteht man es jetzt
Code:
'####################################
'# Projekt IR gesteuertes LED Licht #
'# Copyright 2007 by Stefan Reible #
'####################################
$regfile = "m16def.dat"
$framesize = 32
$swstack = 32
$hwstack = 40
$crystal = 16000000
$baud = 9600
Waitms 50 'Einschwingzeit
'//////////Ports Konfigurieren\\\\\\\\\\
Config Porta = Output 'Multiplexer1
Config Portc = Output 'Multiplexer2
Config Portd.4 = Output 'RGB-Blau
Config Portd.5 = Output 'RGB-Grüen
Config Portd.6 = Output 'RGB-Rot
Config Portd.3 = Input 'TSOP
Porta.4 = 1 'Enable1 active = low
Portc.4 = 1
Enable1 Alias Porta.4
Enable2 Alias Portc.4
Portd.4 = 1 'RGB Led ausschalten
Portd.5 = 1
Portd.6 = 1
'//////////Timer konfigurieren, Vorteiler auf 1\\\\\\\\\\
Config Timer0 = Timer , Prescale = 1
'//////////RC5 konfigurieren mit Timer 2\\\\\\\\\\
Config Rc5 = Pind.3 , Timer = 2
'/////////Sub Deklarieren\\\\\\\\\\\\\
Declare Sub Wait_and_get(byval Ms As Byte)
'//////////Definiere den Interrupthandler\\\\\\\\\\
On Ovf0 Tim0_isr
Enable Interrupts
Enable Timer0 'Timer einschalten
Dim R1 As Byte ' In diese Variablen muss man
Dim G1 As Byte ' im Hauptprogram die gewnschten
Dim B1 As Byte ' Ausgabewerte laden
Dim Z As Word 'Zaehler
Dim Ri1 As Byte 'Hilfsregister
Dim Gi1 As Byte
Dim Bi1 As Byte
'//////////Variablen fr Hauptprogramm\\\\\\\\\\
Dim A As Byte 'Schleifenvariable RGBs
Z = 0
G1 = 0
R1 = 0
B1 = 0
Dim I As Byte 'Schleifenvariable Lauflicht
Dim Ir_address As Byte 'Geraet
Dim Ir_command As Byte 'Befehl
Dim Freilauf As Integer
'//////////Einstellungen\\\\\\\\\\
Freilauf = 10 'Lauflicht Freilaufzeit
'//////////Hauptprogramm <Start>\\\\\\\\\\
Waitms 200
Print "Starte Hauptprogramm"
Standby:
R1 = 0
G1 = 0
B1 = 0
Enable1 = 1
Enable2 = 1
Do
Call Wait_and_get(5) 'Daumchen drehen und auf Befehl warten
Loop
'//////////Hauptprogramm <Ende>\\\\\\\\\\
'//////////Programme <Start>\\\\\\\\\\
'Programm1: RGB LEDs
Programm1:
Enable1 = 1
Enable2 = 1
Do
'Rot
For A = 0 To 254
Incr R1
Waitms 1
Next
Waitms 10
For A = 0 To 254
Decr R1
Waitms 1
Next
Call Wait_and_get(0)
'Grn
For A = 0 To 254
Incr G1
Waitms 1
Next
Waitms 10
For A = 0 To 254
Decr G1
Waitms 1
Next
Call Wait_and_get(0)
'Blau
For A = 0 To 254
Incr B1
Waitms 1
Next
Waitms 10
For A = 0 To 254
Decr B1
Waitms 1
Next
Call Wait_and_get(0)
'Blau/Grn
For A = 0 To 254
Incr B1
Incr G1
Waitms 1
Next
Waitms 10
For A = 0 To 254
Decr B1
Decr G1
Waitms 1
Next
Call Wait_and_get(0)
'Blau/Rot
For A = 0 To 254
Incr B1
Incr R1
Waitms 1
Next
Waitms 10
For A = 0 To 254
Decr B1
Decr R1
Waitms 1
Next
Call Wait_and_get(0)
'Grn/Rot
For A = 0 To 254
Incr G1
Incr R1
Waitms 1
Next
Waitms 10
For A = 0 To 254
Decr G1
Decr R1
Waitms 1
Next
Call Wait_and_get(0)
'Grn/Rot/Blau
For A = 0 To 254
Incr G1
Incr R1
Incr B1
Waitms 1
Next
Waitms 10
For A = 0 To 254
Decr G1
Decr R1
Decr B1
Waitms 1
Next
Loop
'Ende Rgb Fadern
'Programm2: Lauflicht
Programm2:
R1 = 0
G1 = 0
B1 = 0
Enable1 = 1
Enable2 = 1
Do
For I = 0 To 15
Porta = I
Call Wait_and_get(0)
Enable1 = 0
Waitms Freilauf
Enable1 = 1
Next I
For I = 0 To 11
Portc = I
Call Wait_and_get(0)
Enable2 = 0
Waitms Freilauf
Enable2 = 1
Next I
Loop
'ende des 2. programms
'Programm3: Lauflicht2
Programm3:
R1 = 0
G1 = 0
B1 = 0
Enable1 = 1
Enable2 = 1
Do
For I = 0 To 15
Porta = I
Enable1 = 0
Call Wait_and_get(0)
Enable1 = 1
Next I
For I = 0 To 11
Portc = I
Enable2 = 0
Call Wait_and_get(0)
Enable2 = 1
Next I
Loop
'ende lauflicht 2
'Dauer
Dauer:
Do
Enable1 = 0
For I = 0 To 15
Porta = I
Waitus 1
Next I
Enable1 = 1
Enable2 = 0
For I = 0 To 12
Portc = I
Waitus 1
Next I
Enable2 = 1
'Call Wait_and_get(0)
Loop
'Dauer
'//////////Standlicht <Start>\\\\\\\\\\
Programm_rot:
R1 = 255
G1 = 0
B1 = 0
Enable1 = 1
Enable2 = 1
Do
Call Wait_and_get(5)
Loop
Programm_gruen:
R1 = 0
G1 = 0
B1 = 255
Enable1 = 1
Enable2 = 1
Do
Call Wait_and_get(5)
Loop
Programm_gelb:
R1 = 255
G1 = 0
B1 = 255
Enable1 = 1
Enable2 = 1
Do
Call Wait_and_get(5)
Loop
Programm_blau:
R1 = 0
G1 = 255
B1 = 0
Enable1 = 1
Enable2 = 1
Do
Call Wait_and_get(5)
Loop
Programm_pink:
R1 = 255
G1 = 255
B1 = 0
Enable1 = 1
Enable2 = 1
Do
Call Wait_and_get(5)
Loop
'//////////Standlicht <Ende>\\\\\\\\\\
'/////////////////Funktion zum RC5 empfangen und warten <Start>\\\\\\\\\\\\\\\
'Sub zum empfangen und warten
Sub Wait_and_get(byval Ms As Integer)
Getrc5(ir_address , Ir_command) 'Empfangen
'Wenn was empfangen dann reagieren
If Ir_address = 0 Then
Ir_command = Ir_command And &B01111111 'entfernt das togglebit
If Ir_command <> 0 Then Print Ir_command 'IR befehl Printen
If Ir_command = 17 Then Goto Programm1 'RGB Fadern
If Ir_command = 18 Then Goto Programm2
If Ir_command = 19 Then Goto Programm3
If Ir_command = 37 Then Freilauf = Freilauf + 10 'Lauflicht langsamer
If Ir_command = 36 And Freilauf > 9 Then Freilauf = Freilauf -10 'Lauflicht schneller
If Ir_command = 38 Then Goto Programm_rot
If Ir_command = 44 Then Goto Programm_gruen
If Ir_command = 46 Then Goto Programm_gelb
If Ir_command = 51 Then Goto Programm_blau
If Ir_command = 47 Then Goto Programm_pink
If Ir_command = 21 Then Goto Dauer
If Ir_command = 32 Then Goto Standby
End If
Waitms Ms 'warten
End Sub
'/////////////////Funktion zum RC5 empfangen und warten <Ende>\\\\\\\\\\\\\\\
'//////////Interupthandler Timer0 <Start>\\\\\\\\\\
Tim0_isr:
If Z = 0 Then 'Gewnschte Ausgabewerte an
Ri1 = R1 'Hilfsregister bergeben
Gi1 = G1
Bi1 = B1
Z = 255
End If
Z = Z - 1
'PWM Kanaele
'RGB LEDs
If Ri1 > 0 Then
Portd.6 = 0
Else
Portd.6 = 1
End If
Decr Ri1
If Ri1 = 255 Then Ri1 = 0
If Gi1 > 0 Then
Portd.5 = 0
Else
Portd.5 = 1
End If
Decr Gi1
If Gi1 = 255 Then Gi1 = 0
If Bi1 > 0 Then
Portd.4 = 0
Else
Portd.4 = 1
End If
Decr Bi1
If Bi1 = 255 Then Bi1 = 0
Return
'//////////Interupthandler Timer0 <Ende>\\\\\\\\\\
EDIT
Aus der ISR geht ich nicht raus.
Nur aus der Funktion (mit Goto)
Lesezeichen