Hallo zusammen,
mein Projekt ist nun fast abgeschlossen.
Bis auf die Programmierung steht alles, aber wie es immer so ist, als Anfänger, gibt es immer irgentwo ein Problem.
Das folgende Programm funktionierte einwandfrei.
Jetzt wollte ich noch einen Interrupt einbauen, der dann per Subroutine einen RC5 Command emfängt, und dann eine Variable hochzählt!
Leider bekomm ich nichts per RS232 geschickt, und das Hauptprogramm wird auch nicht durchgearbeitet.
Der Interrupt für den RC5 Emfang benutzt Timer1, und die PWM für die RGBs Timer0.
Der TSOP ist auch an Int1 angeschlossen.
Code:$regfile = "m16def.dat" $framesize = 32 $swstack = 32 $hwstack = 32 $crystal = 16000000 $baud = 9600 Waitms 50 'Einschwingzeit '//////////Ports Konfigurieren\\\\\\\\\\ Config Porta = Output 'M1 Config Portc = Output 'M2 Config Rc5 = Pind.3 'TSOP Portd.3 = 1 Config Portd.6 = Output 'RGB-Rot Porta.4 = 1 'Enable1 active = low Portc.4 = 1 Enable1 Alias Porta.4 Enable2 Alias Portc.4 Portd.6 = 1 'RGB Led ausschalten Portc.7 = 1 Portc.6 = 1 '//////////Timer konfigurieren, Vorteiler auf 1\\\\\\\\\\ Config Timer0 = Timer , Prescale = 1 '//////////Definiere den Interrupthandler\\\\\\\\\\ On Ovf0 Tim0_isr Config Int1 = Low Level 'IR Enable Timer0 'Timer einschalten Enable Interrupts Enable Int1 'IR On Int1 Ir_sub Dim R1 As Byte ' In diese Variablen muss man Dim G1 As Byte ' im Hauptprogram die gewünschten Dim B1 As Byte ' Ausgabewerte laden Dim Z As Word 'Zähler Dim Ri1 As Byte ' Hilfsregister Dim Gi1 As Byte Dim Bi1 As Byte '//////////Variablen für Hauptprogramm\\\\\\\\\\ Dim A As Byte 'Schleifenvariable RGBs Z = 0 G1 = 0 R1 = 0 B1 = 0 Dim Addresse As Byte , Kommando As Byte 'RC5 Hilfsvariablen Dim Flag As Bit Flag = 1 Dim I As Byte 'Schleifenvariable Lauflicht Dim Time As Integer Dim Programm As Byte 'Programmauswahl Programm = 0 '//////////Einstellungen\\\\\\\\\\ Time = 100 'Lauflicht Freilaufzeit '//////////Hauptprogramm <Start>\\\\\\\\\\ Print "Starte Hauptprogramm" Do If Programm = 1 Then 'Rot For A = 0 To 254 R1 = R1 + 1 Waitms 1 Next Waitms 10 For A = 0 To 254 R1 = R1 - 1 Waitms 1 Next 'Grün For A = 0 To 254 G1 = G1 + 1 Waitms 1 Next Waitms 10 For A = 0 To 254 G1 = G1 - 1 Waitms 1 Next 'Blau For A = 0 To 254 B1 = B1 + 1 Waitms 1 Next Waitms 10 For A = 0 To 254 B1 = B1 - 1 Waitms 1 Next 'Blau/Grün For A = 0 To 254 B1 = B1 + 1 G1 = G1 + 1 Waitms 1 Next Waitms 10 For A = 0 To 254 B1 = B1 - 1 G1 = G1 - 1 Waitms 1 Next 'Blau/Rot For A = 0 To 254 B1 = B1 + 1 R1 = R1 + 1 Waitms 1 Next Waitms 10 For A = 0 To 254 B1 = B1 - 1 R1 = R1 - 1 Waitms 1 Next 'Grün/Rot For A = 0 To 254 G1 = G1 + 1 R1 = R1 + 1 Waitms 1 Next Waitms 10 For A = 0 To 254 G1 = G1 - 1 R1 = R1 - 1 Waitms 1 Next 'Grün/Rot/Blau For A = 0 To 254 G1 = G1 + 1 R1 = R1 + 1 B1 = B1 + 1 Waitms 1 Next Waitms 10 For A = 0 To 254 G1 = G1 - 1 R1 = R1 - 1 B1 = B1 - 1 Waitms 1 Next End If If Programm = 2 Then For I = 0 To 15 Porta = I Enable1 = 0 Waitms Time Enable1 = 1 Next I For I = 0 To 11 Portc = I Enable2 = 0 Waitms Time Enable2 = 1 Next I End If Loop '//////////Hauptprogramm <Ende>\\\\\\\\\\ '//////////Interupthandler Timer0 <Start>\\\\\\\\\\ Tim0_isr: If Z = 0 Then 'Gewünschte Ausgabewerte an Ri1 = R1 'Hilfsregister übergeben Gi1 = G1 Bi1 = B1 Z = 255 End If Z = Z - 1 'PWM Kanäle 'RGB LEDs If Ri1 > 0 Then Portd.6 = 0 Else Portd.6 = 1 End If Ri1 = Ri1 - 1 If Ri1 = 255 Then Ri1 = 0 If Gi1 > 0 Then Portc.7 = 0 Else Portc.7 = 1 End If Gi1 = Gi1 - 1 If Gi1 = 255 Then Gi1 = 0 If Bi1 > 0 Then Portc.6 = 0 Else Portc.6 = 1 End If Bi1 = Bi1 - 1 If Bi1 = 255 Then Bi1 = 0 Return '//////////Interupthandler Timer0 <Ende>\\\\\\\\\\ '//////////Interupthandler Timer1 <Start>\\\\\\\\\\ Ir_sub: Getrc5(addresse , Kommando) If Flag = 1 Then Print "Fehlerhaftes Kommando" Flag = 0 End If If Addresse <> 255 Then Reset Kommando.7 ' Togglebit zurücksetzen Cls Print "Addresse: " ; Addresse ; " Kommando: " ; Kommando Flag = 1 Programm = Programm + 1 'Programm auswahl End If Return '//////////Interupthandler Timer1 <Ende>\\\\\\\\\\







Zitieren

Lesezeichen