Hallo!
Ich möchte einige Daten per RS232 empfangen und daraus PWMs generieren. Der PWM-Teil funktioniert auch wunderbar, nur habe ich heute die RS232-Empfangsroutine von einfachem Polling in der Hauptschleife auf ein interruptbasiertes Verfahren umstellen wollen. Leider wird der Interruptvektor überhaupt nicht angesprungen. (Die Debug-Message im Interrupt wird nicht ausgegeben). Kann mir jemand sagen, woran das liegt?
Hier der Code
Code:$regfile = "m8def.dat" $crystal = 14745600 $baud = 115200 Config Timer0 = Timer , Prescale = 1 'Timer0 für 100 Hz Config Portb = Output Config Portc = Output Dim Tmp_b As Byte 'Temp-Register für die Outputs (schneller beschreibbar) Dim Tmp_c As Byte Dim Pointer As Byte 'debug Dim Pwm_cnt As Byte 'Zähler für PWM-Intervall Dim Pwms(12) As Byte 'Array mit PWM-Werten Dim Tmp_pwms(12) As Byte 'temporäres pwm-array Dim Incoming As Byte 'Byte welches über UART gekommen ist Dim Mybytes As Byte 'wieviele signifikante bytes hab ich empfangen Dim Bytecnt As Integer 'Wieviele Bytes wurden empfangen? Dim Receiveflag As Bit Bytecnt = 0 Receiveflag = 0 Const Slaveid = 0 'Slave-IDs von 0 bis 24) Const Timervorgabe = 112 'Timerstartwert für korrektes Timing Const Startwert = 1 +(slaveid * 12) 'Hier im Stream fangen meine Bytes an Const Startsymbol = 123 Pwms(1) = 10 'Farbwerte zuweisen (debug) Pwms(2) = 10 Pwms(3) = 10 Pwms(4) = 10 Pwms(5) = 10 Pwms(6) = 10 Pwms(7) = 10 Pwms(8) = 10 Pwms(9) = 10 Pwms(10) = 10 Pwms(11) = 10 Pwms(12) = 10 Waitms 500 Portb.1 = 1 'Takt testen (debug) Waitms 500 Portb.1 = 0 Waitms 500 Portb.1 = 1 Waitms 500 Portb.1 = 0 Waitms 500 Portb.1 = 1 Waitms 500 Portb.1 = 0 Waitms 500 Print Print "RGB-Slave...started" Print "Slave-ID..." ; Slaveid Print "Communication...OK" Print Enable Timer0 Enable Urxc Enable Interrupts Timer0 = Timervorgabe On Timer0 Timer_irq On Urxc Getit 'Main: Do If Receiveflag = 1 Then 'Wenn flag gesetzt ist Pwms(1) = Tmp_pwms(1) 'Array kopieren Pwms(2) = Tmp_pwms(2) Pwms(3) = Tmp_pwms(3) Pwms(4) = Tmp_pwms(4) Pwms(5) = Tmp_pwms(5) Pwms(6) = Tmp_pwms(6) Pwms(7) = Tmp_pwms(7) Pwms(8) = Tmp_pwms(8) Pwms(9) = Tmp_pwms(9) Pwms(10) = Tmp_pwms(10) Pwms(11) = Tmp_pwms(11) Pwms(12) = Tmp_pwms(12) 'mybytes zurücksetzen Mybytes = 0 'flag loeschen Receiveflag = 0 Print Print "Array completely received:" 'debug Print Chr(pwms(1)) ; " / " ; Pwms(1) Print Chr(pwms(2)) ; " / " ; Pwms(2) Print Chr(pwms(3)) ; " / " ; Pwms(3) Print Chr(pwms(4)) ; " / " ; Pwms(4) Print Chr(pwms(5)) ; " / " ; Pwms(5) Print Chr(pwms(6)) ; " / " ; Pwms(6) Print Chr(pwms(7)) ; " / " ; Pwms(7) Print Chr(pwms(8)) ; " / " ; Pwms(8) Print Chr(pwms(9)) ; " / " ; Pwms(9) Print Chr(pwms(10)) ; " / " ; Pwms(10) Print Chr(pwms(11)) ; " / " ; Pwms(11) Print Chr(pwms(12)) ; " / " ; Pwms(12) Print End If Loop Getit: Print "receive" 'debug Incoming = Udr 'Aktuelles Zeichen Speichern Incr Bytecnt 'Hab nen Byte mehr If Incoming = Startsymbol Then Bytecnt = 0 'Startwert ist das Startsymbol des Streams If Bytecnt = Startwert Then Mybytes = 1 'Hier ist mein erstes Byte If Mybytes > 0 Then 'Wenn mein erstes Byte gefunden wurde Tmp_pwms(mybytes) = Incoming 'Byte in temp-Array Incr Mybytes 'Ein Byte mehr gesammelt End If If Mybytes > 12 Then 'wenn alle 12 bytes da sind... Receiveflag = 1 '...flag setzen damit im hauptprogramm die werte übernommen werden End If Return Timer_irq: Timer0 = Timervorgabe Tmp_b = 0 Tmp_c = 0 If Pwms(1) > Pwm_cnt Then Tmp_c = Tmp_c Or 8 'R1 (PORTC.3) If Pwms(2) > Pwm_cnt Then Tmp_c = Tmp_c Or 16 'G1 (PORTC.4) If Pwms(3) > Pwm_cnt Then Tmp_c = Tmp_c Or 32 'B1 (PORTC.1) If Pwms(4) > Pwm_cnt Then Tmp_c = Tmp_c Or 1 'R2 (PORTC.0) If Pwms(5) > Pwm_cnt Then Tmp_c = Tmp_c Or 2 'G2 (PORTC.1) If Pwms(6) > Pwm_cnt Then Tmp_c = Tmp_c Or 4 'B2 (PORTC.2) If Pwms(7) > Pwm_cnt Then Tmp_b = Tmp_b Or 8 'R3 (PORTB.3) If Pwms(8) > Pwm_cnt Then Tmp_b = Tmp_b Or 16 'G3 (PORTB.4) If Pwms(9) > Pwm_cnt Then Tmp_b = Tmp_b Or 32 'B3 (PORTB.5) If Pwms(10) > Pwm_cnt Then Tmp_b = Tmp_b Or 1 'R4 (PORTB.0) If Pwms(11) > Pwm_cnt Then Tmp_b = Tmp_b Or 2 'R3 (PORTB.1) If Pwms(12) > Pwm_cnt Then Tmp_b = Tmp_b Or 4 'R3 (PORTB.2) Portc = Tmp_c Portb = Tmp_b Incr Pwm_cnt 'Pwm_cnt incrementieren und lustig überlaufen lassen Return







Zitieren
Lesezeichen