PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : RC5 Empfang Bascom, zweistellige Zahl



Grave
14.03.2007, 19:58
Hi,
ich möchte mir einen Fernbedienungsempfänger bauen. Den Beispielcode in der Bascom Hilfe habe ich quch soweit verstanden. Mein problem ist folgendes:

Wenn ich zum Beispiel mit meiner Fernbedienung die Zahl "23", also zuerst die 2 dann die 3, senden will, wie soll ich das in Bascom realisieren. Soweit ich weiß bleibt die Abarbeitung des Quellcodes bei dem Befehl "GetRC5" stehen, bis ein Signal empfangen wird.
Wenn ich diesen Befehl zweimal hintereinander aufrufe könnte ich ja zweistellige Zahlen empfangen. Sende ich aber nur eine einstellige Zahl, würde das Programm ja auf eine zweite Sendesequenz warten.

Ich hoffe, man kann mein Problem verstehen.

Gruß Grave

P_II
14.03.2007, 20:26
Soweit ich weiß, kann man jede zahl bis 255 oder 254 schicken und auch empfangen. des musst du nich auf zweimal machen.

Nach ner bestimmten zeit liefert getrc5 255 zurück. als fehler so zu sagen und des Programm läuft weiter.

Ist alles schon ein bissele her, aber ich hoffe es stimmt so und hilft dir.

Gruß P_II

jar
14.03.2007, 21:51
du musst das toggle bit auswerten , das wär dann 2 Tastendrücke, wenn du es nicht tust, dann ist das ein tastendruck, geht auch, zum beispiel für Counter hochzählen

beispiel code hätte ich bei bedarf

aber natürlich nicht genau für deine anwendung, TV verlangen dafür das vorne weg ein umschalt code gesendet wird ./.. für 2 stellige sender, dann wird auf die 2te taste gewartet, oder du änderst die routine im empfand so das das 2te zeichen innerhal einer kurzen zeit nach kommt, sonst wird das erste zeichen ausgeführt...

Grave
15.03.2007, 05:49
Ich brauch das nicht für TV. Ich muß so ca. 40 LED´s ein und ausschalten. Ich wollte zwei IC´s hintereinnander schalten. Ich weiß, sowas könnte man auch mit Schieberegistern machen.
Würde mal gerne deinen Code sehen.


oder du änderst die routine im empfand so das das 2te zeichen innerhal einer kurzen zeit nach kommt, sonst wird das erste zeichen ausgeführt...

Genau das. Aber wie???

jar
15.03.2007, 11:13
Ich brauch das nicht für TV. Ich muß so ca. 40 LED´s ein und ausschalten. Ich wollte zwei IC´s hintereinnander schalten

Würde mal gerne deinen Code sehen.

oder du änderst die routine im empfand so das das 2te zeichen innerhal einer kurzen zeit nach kommt, sonst wird das erste zeichen ausgeführt...
Genau das. Aber wie???


brauchst du wirklich 2 IC ? 40 sind
6x7 oder 5x8 Ports bleiben in Summe 13 nötige Portpins, die als Kreuzungsmatrix einer aus 5 High Zeilen, einer aus 8 low Spalten, schaltet genau eine LED on, kann man natürlich mit 2x 8Bit I2C zu parallel machen



grün funzt , getestet
rot ungetestet, sollte klappen


$regfile = "2313def.dat" ' specify the used micro
$crystal = 4000000 ' used crystal frequency
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space

Ddrb = &H1F
Ddrd = 251

Config Rc5 = Pind.2 'RC5_input
Portd.0 = 0 'toogle Bit Led Aus
Portb.0 = 1 'Cam Auslöseport high

Enable Interrupts
Declare Sub Dimm_pwm

Dim Address As Byte , Command As Byte , Oldaddress As Byte , Oldtoggle As Byte, Oldcommand As Byte
Dim Led_hell As Byte
Dim A As Byte , Count As Long
Dim Strcount As String * 12

Led_hell = 250

Oldaddress = 0
Oldcommand = 0

Oldtoggle=0

'define the used constants
'I used portA for testing
'Const _lcdport = Portb
'Const _lcdddr = Ddrb
'Const _lcdin = Pinb
'Const _lcd_e = 1
'Const _lcd_rw = 2
'Const _lcd_rs = 3

'this is like always, define the kind of LCD
Config Lcd = 20 * 4 'other options are 16 * 2 , 16 * 4 and 20 * 4, 20 * 2 , 16 * 1a
Config Lcdpin = Pin , Db7 = Portd.6 , Db6 = Portd.5 , Db5 = Portd.4 , Db4 = Portb.4 , E = Portb.2 , Rs = Portb.1
Rem with the config lcdpin statement you can override the compiler settings
'[COMPILER-LCD]
'DB7=PORTB.7
'DB6=PORTB.6
'DB5=PORTB.5
'DB4=PORTB.4
'E=PORTB.2
'RS=PORTB.1

Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Down , Prescale = 8

'and here some simple lcd code
Cursor Off Noblink
Cls
Locate 1 , 1 : Lcd "35tes " 'display this at the top line
Count = 0
Compare1a = Led_hell

'Call Dimm_pwm

Do
Getrc5(address , Command)
If Address < 255 Then
If Command.7 = 1 Then



if Command.7<> Oldtoggle then
Oldtoggle=Command.7
'hier kommt 1ter Tastendruck mit Adress Command kann was gemacht werden
else
'hier kommt 2ter Tastendruck mit Adress Command kann was anderes gemacht werden
endif



Portd.0 = 1 : Command.7 = 0

Else
Portd = 0
End If
If Count <= 1000 Then
Count = Count + 1
Strcount = Str(count)
Else
Strcount = ">1000"
End If
A = 20 - Len(strcount)
Locate 1 , 15
Lcd " "
Locate 1 , A
Lcd Strcount

Locate 3 , 1 : Lcd "Address=" ;
Locate 4 , 1 : Lcd "Command=" ;

If Address = 7 And Command = 6 And Led_hell < 245 Then Led_hell = Led_hell + 10
If Address = 7 And Command = 12 And Led_hell > 10 Then Led_hell = Led_hell - 10
Compare1a = Led_hell
Locate 1 , 10 : Lcd " "
Locate 1 , 10 : Lcd Led_hell
Locate 3 , 9 : Lcd Address
Locate 4 , 9 : Lcd Command
If Command <> Oldcommand Or Address <> Oldaddress Then
Oldcommand = Command
Oldaddress = Address
Locate 2 , 1 : Lcd " "
Locate 2 , 1 : Lcd "Old..."
Locate 2 , 7 : Lcd Oldaddress ; " ..."
Locate 2 , 11 : Lcd Oldcommand ; " ..."
Locate 2 , 15 : Lcd "Wait"
Count = 0
End If

If Address = 7 And Command = 54 Then
Toggle Portb.0
Waitms 500
Toggle Portb.0
End If

Else
Locate 3 , 9 : Lcd " "
Locate 4 , 9 : Lcd " "
End If
Loop
End

Sub Dimm_pwm

Dim I As Byte , J As Byte

For I = 1 To 2
For J = 255 To 64 Step -10
Compare1a = J
Waitms 10
Next J
Wait 1
For J = 64 To 255 Step 10
Compare1a = J
Waitms 10
Next J
Wait 1
Next I


End Sub

Grave
15.03.2007, 20:02
Soweit ich denn Code verstehe, besteht mein Problem aber immer noch.

Do
Getrc5(address , Command)
If Address < 255 Then
If Command.7 = 1 Then

if Command.7<> Oldtoggle then
Oldtoggle=Command.7
'hier kommt 1ter Tastendruck mit Adress Command kann was gemacht werden
else
'hier kommt 2ter Tastendruck mit Adress Command kann was anderes gemacht werden

If Address = 7 And Command = 1 Then
Toggle Portb.0
Waitms 500
Toggle Portb.0
End If

If Address = 7 And Command = 13 Then
Toggle Portb.13
Waitms 500
Toggle Portb.13
End If

Loop
End

Wenn ich jetzt Commande 1 sende, also Taste 1 drücke, funktioniert das ganze ja. Wenn ich jetzt aber Portb.13, oder welchen auch immer aktivieren will, sende ich commande 1 und sofort danach 3, sprich Taste 1 und Taste 3, funktioniert das nicht, oder?

Jetzt würde er doch Portb.0 ändern und nicht Portb.13?!

Was ich bräuchte, wäre eine Zeitabhängige If-Abfrage, so wie:
Prüfe für die nächste Sekunde, ob ein IR-Signal empfangen werden kann, und wenn nicht, dann mach weiter.

Grave
16.03.2007, 21:56
Blöde Frage!! ht sich erledigt