HELP! Basic stamp, ik kan er niks mee
Geplaatst: di 28 nov 2006, 23:43
Ik ben bezig met een projectje om een basic stamp te gebruiken om 2 servomotoren aan te sturen. dit is geen probleem en dit werkt ook al.
Wat ik nu wil bereiken is het volgende:
Ik wil met een philips (RC5) afstandsbediening een opdracht geven en de basicstamp moet dit verwerken. dit klinkt makkelijk maar ik kom er niet uit!
Wat wil ik weten?
Uit het philips protocol komt naar voren dat er eerst een startbit komt. Dan volgt er een togglebit om vervolgens een reeks van 5 bitjes te sturen waar de machinecode in zit. de laatste bitstroom van 6 bitjes bevat de werkelijke instructie.
Ik zou graag willen weten hoe ik de bitstroom opvang in een geheugen of register en hoe ik de voor mij relevante informatie verwerk zodat ik handelingen aan de opdrachten kan koppelen.
nu heb ik het volgende programma gevonden wat iets doet met de rc5 code:
' ==============================================================================
'
' File...... IRB RC-5 Control.BS2
' Purpose... Simple RC-5 Control Demonstration
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 25 NOV 2002
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ==============================================================================
' ------------------------------------------------------------------------------
' Program Description
' ------------------------------------------------------------------------------
' This program uses the Parallax IR Buddy to receive and decode RC-5 commands
' from a multi-function remote control. Numbers 1 - 4 are converted into pin
' controls. LEDs are used to display the state of each control pin.
'
' This program is system code sensitive, allowing the same remote to indepen-
' dently control multiple projects without interference.
'
' Remote #1 toggles pin 0
' Remote #2 toggles pin 1
' Remote #3 toggles pin 2
' Remote #4 toggles pin 3
'
' Note that repeated keys are ignored to prevent possible problems from rapid
' toggling of the device connected to the IO control pin.
' ------------------------------------------------------------------------------
' Revision History
' ------------------------------------------------------------------------------
' ------------------------------------------------------------------------------
' I/O Definitions
' ------------------------------------------------------------------------------
IRbSIO PIN 15 ' IR Buddy serial I/O
Ports VAR OUTA ' LED / device control pins
Port1 PIN 0
Port2 PIN 1
Port3 PIN 2
Port4 PIN 3
' ------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------
IRbRc5Rx CON $72 ' RC5 protocol RX
IRb96 CON 84 + $8000 ' 9600 baud, open
IRb48 CON 188 + $8000 ' 4800 baud, open
IRb24 CON 396 + $8000 ' 2400 baud, open
IRbBaud CON IRb96
BufEnd CON 254 ' end of buffer
System CON 0 ' system code for this Stamp
LedOn CON 1
LedOff CON 0
AllOn CON %1111
AllOff CON %0000
Mute CON 13 ' "Mute" key on Philips remote
' ------------------------------------------------------------------------------
' Variables
' ------------------------------------------------------------------------------
buffer VAR Byte(8) ' RC-5 RX buffer
idx VAR Nib ' loop counter
sysCode VAR Byte ' received system code
cmdCode VAR Byte ' received command code
' ------------------------------------------------------------------------------
' EEPROM Data
' ------------------------------------------------------------------------------
' ------------------------------------------------------------------------------
' Initialization
' ------------------------------------------------------------------------------
Setup:
Ports = AllOff ' all outputs off
DIRA = %1111 ' all ports are outputs
GOSUB IR_Buddy_Reset
' ------------------------------------------------------------------------------
' Program Code
' ------------------------------------------------------------------------------
Main:
DO
SEROUT IRbSIO, IRbBaud, [IRbRc5Rx, 10] ' start RC-5 RX
SERIN IRbSIO, IRbBaud, [STR buffer\8\255] ' get data
GOSUB Process_Commands
PAUSE 500 ' give IR Buddy time to work
LOOP
END
' ------------------------------------------------------------------------------
' Subroutines
' ------------------------------------------------------------------------------
Process_Commands:
FOR idx = 0 TO 6 STEP 2
sysCode = buffer(idx) ' extract system code
IF (sysCode = System) THEN ' system valid, check command
cmdCode = buffer(idx + 1) ' extract command
SELECT cmdCode ' compare with good values
CASE 1 TO 4 ' numbers 1 - 4
TOGGLE (cmdCode - 1)
CASE Mute ' "Mute" button
Ports = AllOff
ENDSELECT
ENDIF
NEXT
RETURN
' Reset the IR Buddy. This code is useful for clearing data from the RX
' buffer and prepping to switch modes. Timing specific; do not change.
IR_Buddy_Reset:
LOW IRbSIO ' signal reset
PAUSE 5
INPUT IRbSIO ' release reset signal
PAUSE 50 ' allow time for reset actions
RETURN
Bovenstaand programma vangt dus wel iets op alleen het moet nog verwerkt worden zodat er ook een handeling aan de opdracht wordt gekoppeld. Zou iemand dit programma kunnen verduidelijken wat het nu precies doet?
Al vast bedankt voor de moeite! en ik bied een taartje voor de gene met het verlossende antwoord!
Wat ik nu wil bereiken is het volgende:
Ik wil met een philips (RC5) afstandsbediening een opdracht geven en de basicstamp moet dit verwerken. dit klinkt makkelijk maar ik kom er niet uit!
Wat wil ik weten?
Uit het philips protocol komt naar voren dat er eerst een startbit komt. Dan volgt er een togglebit om vervolgens een reeks van 5 bitjes te sturen waar de machinecode in zit. de laatste bitstroom van 6 bitjes bevat de werkelijke instructie.
Ik zou graag willen weten hoe ik de bitstroom opvang in een geheugen of register en hoe ik de voor mij relevante informatie verwerk zodat ik handelingen aan de opdrachten kan koppelen.
nu heb ik het volgende programma gevonden wat iets doet met de rc5 code:
' ==============================================================================
'
' File...... IRB RC-5 Control.BS2
' Purpose... Simple RC-5 Control Demonstration
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 25 NOV 2002
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ==============================================================================
' ------------------------------------------------------------------------------
' Program Description
' ------------------------------------------------------------------------------
' This program uses the Parallax IR Buddy to receive and decode RC-5 commands
' from a multi-function remote control. Numbers 1 - 4 are converted into pin
' controls. LEDs are used to display the state of each control pin.
'
' This program is system code sensitive, allowing the same remote to indepen-
' dently control multiple projects without interference.
'
' Remote #1 toggles pin 0
' Remote #2 toggles pin 1
' Remote #3 toggles pin 2
' Remote #4 toggles pin 3
'
' Note that repeated keys are ignored to prevent possible problems from rapid
' toggling of the device connected to the IO control pin.
' ------------------------------------------------------------------------------
' Revision History
' ------------------------------------------------------------------------------
' ------------------------------------------------------------------------------
' I/O Definitions
' ------------------------------------------------------------------------------
IRbSIO PIN 15 ' IR Buddy serial I/O
Ports VAR OUTA ' LED / device control pins
Port1 PIN 0
Port2 PIN 1
Port3 PIN 2
Port4 PIN 3
' ------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------
IRbRc5Rx CON $72 ' RC5 protocol RX
IRb96 CON 84 + $8000 ' 9600 baud, open
IRb48 CON 188 + $8000 ' 4800 baud, open
IRb24 CON 396 + $8000 ' 2400 baud, open
IRbBaud CON IRb96
BufEnd CON 254 ' end of buffer
System CON 0 ' system code for this Stamp
LedOn CON 1
LedOff CON 0
AllOn CON %1111
AllOff CON %0000
Mute CON 13 ' "Mute" key on Philips remote
' ------------------------------------------------------------------------------
' Variables
' ------------------------------------------------------------------------------
buffer VAR Byte(8) ' RC-5 RX buffer
idx VAR Nib ' loop counter
sysCode VAR Byte ' received system code
cmdCode VAR Byte ' received command code
' ------------------------------------------------------------------------------
' EEPROM Data
' ------------------------------------------------------------------------------
' ------------------------------------------------------------------------------
' Initialization
' ------------------------------------------------------------------------------
Setup:
Ports = AllOff ' all outputs off
DIRA = %1111 ' all ports are outputs
GOSUB IR_Buddy_Reset
' ------------------------------------------------------------------------------
' Program Code
' ------------------------------------------------------------------------------
Main:
DO
SEROUT IRbSIO, IRbBaud, [IRbRc5Rx, 10] ' start RC-5 RX
SERIN IRbSIO, IRbBaud, [STR buffer\8\255] ' get data
GOSUB Process_Commands
PAUSE 500 ' give IR Buddy time to work
LOOP
END
' ------------------------------------------------------------------------------
' Subroutines
' ------------------------------------------------------------------------------
Process_Commands:
FOR idx = 0 TO 6 STEP 2
sysCode = buffer(idx) ' extract system code
IF (sysCode = System) THEN ' system valid, check command
cmdCode = buffer(idx + 1) ' extract command
SELECT cmdCode ' compare with good values
CASE 1 TO 4 ' numbers 1 - 4
TOGGLE (cmdCode - 1)
CASE Mute ' "Mute" button
Ports = AllOff
ENDSELECT
ENDIF
NEXT
RETURN
' Reset the IR Buddy. This code is useful for clearing data from the RX
' buffer and prepping to switch modes. Timing specific; do not change.
IR_Buddy_Reset:
LOW IRbSIO ' signal reset
PAUSE 5
INPUT IRbSIO ' release reset signal
PAUSE 50 ' allow time for reset actions
RETURN
Bovenstaand programma vangt dus wel iets op alleen het moet nog verwerkt worden zodat er ook een handeling aan de opdracht wordt gekoppeld. Zou iemand dit programma kunnen verduidelijken wat het nu precies doet?
Al vast bedankt voor de moeite! en ik bied een taartje voor de gene met het verlossende antwoord!