Transmitting SIRCS code (SX/B 2.0 demo)
JonnyMac
Posts: 9,527
No, SIRCS (Sony IR Control System) commands are not built into SX/B 2.0 but I have been using SX/B to create devices that do and taking advantage of a new -- a little advanced -- method of declaring variables.
From time-to-time users will wonder how they've run out of program space when they haven't. The "problem" is that we (especially me) often create a chunk of temporary variables to use in subroutines that cut into our normal program variables. While SX/B 2.0 does support local variables it comes with overhead so I use a new feature that lets us declare bytes AND words inside an array. Now, the are rules to doing this, but they're not difficult.
In my TX_SIRCS program I have an array that is used just for the IR stuff (fixed, thanks Peter):
By using the @ modifier we're able to declare bytes and words inside an array. The rule, though, is this: we have to be inside that bank to work with those variables -- if we're not inside the irTemp bank when attempting to access these variables weird things can happen (trust me on this).
Here's the subroutine that transmits the SIRCS code (you could use this to control your TV or similar device).
You can see that at the top of this subroutine I switch to the irTemp bank -- again using @. When all is done we switch back to the default bank before returning to the caller.
Why go through all this trouble? To save space in the default RAM area (which is just 19 bytes on the SX28).
For those interested in this program it uses an 80kHz interrupt to modulate the IR Led and update the 45ms frame timer (in assembly). I have a big project in the March issue of Nuts & Volts that uses the 20-bit version of this routine (the project is a time-lapse controller for my Sony digital SLR).
Post Edited (JonnyMac) : 1/28/2009 9:43:52 PM GMT
From time-to-time users will wonder how they've run out of program space when they haven't. The "problem" is that we (especially me) often create a chunk of temporary variables to use in subroutines that cut into our normal program variables. While SX/B 2.0 does support local variables it comes with overhead so I use a new feature that lets us declare bytes AND words inside an array. Now, the are rules to doing this, but they're not difficult.
In my TX_SIRCS program I have an array that is used just for the IR stuff (fixed, thanks Peter):
irTemp VAR Byte (5) BANK irFrameTmr VAR Word @irTemp(0) ' 45ms frame timer irDevice VAR Byte @irTemp(2) ' SIRCS device code (5-bits) irKey VAR Byte @irTemp(3) ' SIRCS key code (7-bits) irBits VAR Byte @irTemp(4) ' loop controller
By using the @ modifier we're able to declare bytes and words inside an array. The rule, though, is this: we have to be inside that bank to work with those variables -- if we're not inside the irTemp bank when attempting to access these variables weird things can happen (trust me on this).
Here's the subroutine that transmits the SIRCS code (you could use this to control your TV or similar device).
' Use: TX_SIRCS device, key
' -- transmit 12-bit (device + key) SIRCS code
SUB TX_SIRCS
BANK @irTemp ' switch to IR vars
irDevice = __PARAM1 ' capture parameters
irKey = __PARAM2
irFrameTmr = MS_450 ' start frame timer
' start bit
IrAnode = IR_ENABLE ' activate IR LED
DELAY MS_024 ' wait 2.4 ms
IrAnode = IR_DISABLE ' deactivate IR LED
DELAY MS_006 ' wait 0.6 ms
' send key code
FOR irBits = 1 TO 7 ' send 7 bits
IrAnode = IR_ENABLE ' activate IR LED
IF irKey.0 = 1 THEN ' if 1
DELAY MS_012 ' wait 1.2 ms
ELSE ' otherwise
DELAY MS_006 ' wait 0.6 ms
ENDIF
IrAnode = IR_DISABLE ' deactivate IR LED
DELAY MS_006
irKey = irKey >> 1 ' get next bit
NEXT
' send device code
FOR irBits = 1 TO 7 ' send 5 bits
IrAnode = IR_ENABLE ' activate IR LED
IF irDevice.0 = 1 THEN ' if 1
DELAY MS_012 ' wait 1.2 ms
ELSE ' otherwise
DELAY MS_006 ' wait 0.6 ms
ENDIF
IrAnode = IR_DISABLE ' deactivate IR LED
DELAY MS_006
irDevice = irDevice >> 1 ' get next bit
NEXT
DO WHILE irFrameTmr > 0 ' let frame timer expire
LOOP
BANK ' back to default bank
ENDSUB
You can see that at the top of this subroutine I switch to the irTemp bank -- again using @. When all is done we switch back to the default bank before returning to the caller.
Why go through all this trouble? To save space in the default RAM area (which is just 19 bytes on the SX28).
For those interested in this program it uses an 80kHz interrupt to modulate the IR Led and update the 45ms frame timer (in assembly). I have a big project in the March issue of Nuts & Volts that uses the 20-bit version of this routine (the project is a time-lapse controller for my Sony digital SLR).
Post Edited (JonnyMac) : 1/28/2009 9:43:52 PM GMT


Comments
I presume you mean to use
Without the indexes, all variables will be at address irTemp(0)
regards peter
·