Examples Index

               

' =========================================================================
'
'   File...... SIRCS.SXB
'   Purpose... Sony IRCS decoder
'   Author.... (c) Parallax, Inc. -- All Rights Reserved
'   E-mail.... support@parallax.com
'   Started...
'   Updated... 05 JUL 2006
'
' =========================================================================

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Receives and decodes Sony IR Control System stream from IR demodulator.
' Decodes 12 bits, displays lower seven on LEDs.
'
' References:
' -- http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv76.pdf
' -- http://www.parallax.com/dl/docs/books/edu/IRRemoteBoebot.pdf

' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ            4_000_000
ID              "SIRCS"

' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

IR              VAR     RA.0                    ' IR input
Leds            VAR     RBC                     ' LEDs on RB/RC

' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

StartBit	CON	216			' 90% of 2400 uS
OneBit		CON	108			' 90% of 1200 uS
ZeroBit		CON	 54                     ' 90% of  600 uS

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

irCode          VAR     Word                    ' entire code
cmdCode         VAR     irCode_LSB              ' IR command code (7 bits)
devCode         VAR     irCode_MSB              ' IR device code (5 bits)

tmpB1           VAR     Byte                    ' subroutine work vars
tmpB2           VAR     Byte
tmpB3           VAR     Byte
tmpW1           VAR     Word

' =========================================================================
  PROGRAM Start
' =========================================================================

' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------

GET_IR_PULSE    SUB     0                       ' get pulse from IR pin
GET_SIRCS       FUNC    2                       ' get code from SIRCS

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  PLP_A = %0001                                 ' pull-up unused pins
  TRIS_B = %00000000                            ' make LED pins outputs
  TRIS_C = %00000000

Main:
  DO
    Leds = GET_SIRCS                            ' get and show IR code
  LOOP
  END

' -------------------------------------------------------------------------
' Subroutine Code
' -------------------------------------------------------------------------

' pulseWidth = GET_IR_PULSE
' -- waits for and measures 1-0-1 pulse on IR pin
' -- return value (0 to 255) is in 10 uS units

GET_IR_PULSE:
  PULSIN IR, 0, tmpB1                           ' wait for pulse
  RETURN tmpB1                                  ' return to caller

' -------------------------------------------------------------------------

' GET_SIRCS
' -- waits for Sony IRCS input stream
' -- puts 7-bit command into LSB of return value
' -- puts 5-bit device code into MSB of return value

GET_SIRCS:
  tmpW1 = 0                                     ' clear working output
  DO
    tmpB2 = GET_IR_PULSE                        ' get bit from IR
  LOOP UNTIL tmpB2 >= StartBit                  ' loop until valid start bit
  FOR tmpB3 = 0 TO 6                            ' get 7-bit code
    tmpW1_LSB = tmpW1_LSB >> 1                  ' prep for LSB
    tmpB2 = GET_IR_PULSE                        ' measure data bit
    IF tmpB2 >= OneBit THEN                     ' valid "1" bit
      tmpW1_LSB.6 = 1                           '   yes, set the bit
    ENDIF
  NEXT
  FOR tmpB3 = 0 TO 4                            ' get 5-bit code
    tmpW1_MSB = tmpW1_MSB >> 1                  ' prep for LSB
    tmpB2 = GET_IR_PULSE                        ' measure data bit
    IF tmpB2 >= OneBit THEN                     ' valid "1" bit
      tmpW1_MSB.4 = 1                           '   yes, set the bit
    ENDIF
  NEXT
  RETURN tmpW1