habe schon asm-schnippsel mit reingebracht beim rc5-senden. jetzt geht es mit dem empfängerprogramm welches im anhang ist (aus diesem forum). irgendwie muss ich jetzt noch eine asm-schleife finden für die (5bit) adresswerte und die (6bit) command-werte.
der Getrc5(address , Command) von basocm ist ein bisschen eirig, also selbst proggen ist machmal besser in bascom.
aber das selbsterstellte einleseprogramm vom rc5-code ist super , übersetzt den code fehlerfrei.
empfängerprogramm :Code:$regfile = "m32def.dat" $framesize = 32 $swstack = 32 $hwstack = 64 $crystal = 8000000 Config Timer1 = Timer , Prescale = 1 , Compare A = Toggle , Clear Timer = 1 Declare Sub Rc5out() Dim Adre As Byte Dim Command As Byte Dim Togglebit As Byte Enable Interrupts Compare1a = 111 Do Adre = 13 Togglebit = 0 Command = 37 Call Rc5out() Waitms 500 Loop End Sub Rc5out() ' 2x hi !Call Bit_hi !Call Bit_hi ' toglebit lds r17,{togglebit} sbrs r17,0 !call bit_lo sbrc r17,0 !call bit_hi ' 5x adresse lds r17,{adre} sbrs r17,4 !call bit_lo sbrc r17,4 !call bit_hi sbrs r17,3 !call bit_lo sbrc r17,3 !call bit_hi sbrs r17,2 !call bit_lo sbrc r17,2 !call bit_hi sbrs r17,1 !call bit_lo sbrc r17,1 !call bit_hi sbrs r17,0 !call bit_lo sbrc r17,0 !call bit_hi ' 6x command lds r17,{command} sbrs r17,5 !call bit_lo sbrc r17,5 !call bit_hi sbrs r17,4 !call bit_lo sbrc r17,4 !call bit_hi sbrs r17,3 !call bit_lo sbrc r17,3 !call bit_hi sbrs r17,2 !call bit_lo sbrc r17,2 !call bit_hi sbrs r17,1 !call bit_lo sbrc r17,1 !call bit_hi sbrs r17,0 !call bit_lo sbrc r17,0 !call bit_hi !Call Ende_rc5 Bit_hi: Config Timer1 = Timer , Prescale = 1 , Compare A = Clear , Clear Timer = 1 Waitus 889 Config Timer1 = Timer , Prescale = 1 , Compare A = Toggle , Clear Timer = 1 Waitus 889 ret Bit_lo: Config Timer1 = Timer , Prescale = 1 , Compare A = Toggle , Clear Timer = 1 Waitus 889 Config Timer1 = Timer , Prescale = 1 , Compare A = Clear , Clear Timer = 1 Waitus 889 ret Ende_rc5: Config Timer1 = Timer , Prescale = 1 , Compare A = Clear , Clear Timer = 1 Waitms 50 End Sub
Code:$regfile = "m32def.dat" $framesize = 32 $swstack = 32 $hwstack = 64 $crystal = 8000000 $baud = 19200 Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.6 , Rs = Portc.7 Config Lcd = 20 * 2 Config Portd.2 = 0 Input_pin Alias Pind.2 'Pin für TSOP1736 Config Timer0 = Timer , Prescale = 8 On Timer0 Timer_irq Const Timervorgabe = 78 'Timeraufruf alle 178µs (10 Samples = 1 Bit = 1,778ms) Enable Timer0 Enable Interrupts 'Timing für 10 Samples Per Bit = 1,778ms Const Samples_early = 8 'Flanke Frühestens Nach 8 Samples Const Samples_late = 12 'Flanke Spätestens Nach 12 Samples Const Samples_min = 3 'Flanke Vor 3 Samples - > Paket Verwerfen 'Variablen der ISR Dim Sample As Byte 'eigentlich Bit, spart aber 46Byte ROM Dim Ir_lastsample As Byte 'zuletzt gelesenes Sample Dim Ir_bittimer As Byte 'zählt die Aufrufe von Timer_IRQ Dim Ir_data_tmp As Word 'Bitstream Dim Ir_bitcount As Byte 'Anzahl gelesener Bits 'Rückgabewerte der ISR Dim Address_rc5 As Byte Dim Command_rc5 As Byte Dim Rc5_flag As Bit Cls Lcd "test" Do If Rc5_flag = 1 Then Reset Rc5_flag Cls 'Print "toggle:" ; Command_rc5.7; 'clear the toggle bit Command_rc5 = Command_rc5 And &B01111111 Lcd " Adr:" ; Address_rc5 ; " Code:" ; Command_rc5 End If 'Waitms 100 Loop End Timer_irq: Timer0 = Timervorgabe Sample = Not Input_pin 'bittimer erhöhen (bleibt bei 255 stehen) If Ir_bittimer < 255 Then Incr Ir_bittimer 'flankenwechsel erkennen If Ir_lastsample <> Sample Then If Ir_bittimer <= Samples_min Then 'flanke kommt zu früh: paket verwerfen Ir_bitcount = 0 Else 'nur Flankenwechsel in Bit-Mitte berücksichtigen If Ir_bittimer >= Samples_early Then If Ir_bittimer <= Samples_late Then 'Bit speichern Shift Ir_data_tmp , Left , 1 Ir_data_tmp = Ir_data_tmp + Sample Incr Ir_bitcount Else 'Flankenwechsel zu spät: Neuanfang mit gemessener Flanke Ir_bitcount = 1 Ir_data_tmp = Sample End If 'bittimer zurücksetzen wenn Timer > Samples_early Ir_bittimer = 0 End If End If 'Kontrolle des Startbits auf 1 If Ir_bitcount = 1 Then Ir_bitcount = Ir_data_tmp.0 'Alle 14 Bits gelesen? If Ir_bitcount >= 14 Then Command_rc5 = Ir_data_tmp 'Bit 6 und 7 siehe unten Shift Ir_data_tmp , Right , 6 Address_rc5 = Ir_data_tmp And &B00011111 'For extended RC5 code, the extended bit is bit 6 of the command. Command_rc5.6 = Not Ir_data_tmp.6 'The toggle bit is stored in bit 7 of the command Command_rc5.7 = Ir_data_tmp.5 'Paket erfolgreich gelesen Set Rc5_flag 'paket zurücksetzen Ir_bitcount = 0 End If End If 'sample im samplepuffer ablegen Ir_lastsample = Sample Return







Zitieren
Lesezeichen