PIC Beginner - Infrared Receiver and IR Protocol


Results 1 to 18 of 18

Threaded View

  1. #3
    Join Date
    Aug 2009
    Posts
    9


    Did you find this post helpful? Yes | No

    Default PIC Beginner - Infrared Receiver and IR Protocol SONY AND NEC

    Thanks for reply

    IR LED circuitry is here.( please see attachment ).

    I use this circuit and test Sony Protocol. LED is blink for any key and correct key code is accept in PC via RS232.

    Here is code for Sony.

    'start code for Sony Protocol --------------------------------------------------------------

    'PIC 16F84A Sony SIRC Protocol

    Include "Modedefs.Bas"
    Define OSC 4 ' Set Xtal Frequency

    Header var word
    Body var word
    i var byte
    tmp var Byte
    irButton var byte
    irDevice var byte

    irIN var PortA.2 'IR Input
    ToCOM var PortB.4 'Serial Data to compute COM port [RS232]

    'next time use both Sony and NEC Protocol in a PIC
    'Same Key from different remote do different tasks
    'eg Key 1 from Sony Remote ----> task1 in PC
    ' Key 1 from NEC Remote -----> task2 in PC

    'SonyLED is blink for Sony and nec LED is blink for NEC Remote
    SonyLED var PortB.2 'Green LED for Sony Remote keypress
    necLED var PortB.3 'Red LED for NEC Remote keypress (Reserved)

    TrisA = %00000100 ' Input RA2 only
    TrisB = 0 ' Output All Port B

    Start:
    LOW SONYLED : LOW NECLED
    IRBUTTON=255: IRDEVICE=255

    'in Header is Sony 240
    Pulsin irin,0,header ' Measure the header length.
    if header > 270 or header < 200 then goto Start

    'if correct header read body 12 bit
    for i =0 to 11
    pulsin irin,0,tmp ' Measure the body length.
    if tmp >= 90 then
    Body.0[i]=1 'in Sony Logic 1 is 120
    else
    Body.0[i]=0 'in Sony Logic 0 is 60
    endif
    next

    IRBUTTON = Body & %01111111 'Mask 7 bit
    IRDEVICE = (Body >>7) & %00011111 'Mask 5 bit

    If IRDEVICE=255 then goto start

    Serout ToCom ,N9600,[IRBUTTON] 'to PC COM - Port

    if IRBUTTON >=0 and IRBUTTON < 255 then
    high Sonyled
    pause 300
    low Sonyled
    endif

    pause 100
    goto start


    'end of code for Sony Protocol ------------------------------------------------------

    I use this circuit again for NEC or CHINA DVD Remote Control.

    ' start code for NEC OR that DVD REMOTE -----------------------------
    'PIC 16F84A NEC Protocol Protocol

    Include "Modedefs.Bas"
    Define OSC 4 ' Set Xtal Frequency

    DEFINE PULSIN_MAX 968 '>968 RETURNS 0

    Header var word
    Body var word
    i var byte
    tmp var Byte
    irButton var byte
    irDevice var byte

    irIN var PortA.2 'IR Input
    ToCOM var PortB.4 'Serial Data to compute COM port [RS232]

    'nec LED is blink for NEC Remote
    necLED var PortB.3 'Red LED for NEC Remote keypress

    TrisA = %00000100 ' Input RA2 only
    TrisB = 0 ' Output All Port B

    Start:
    LOW NECLED
    IRBUTTON=255: IRDEVICE=255

    'in Header is NEC 900
    Pulsin irin,0,header ' Measure the header length.
    if header < 792 then goto Start

    While irIN=0:Wend 'wait pulse

    'if correct header read body 32 bit
    for i =0 to 31
    pulsin irin,0,tmp ' Measure the body length.

    If ((tmp<40) Or (tmp>180)) Then start

    if tmp >= 75 then
    Body.0[i]=1
    endif
    next

    IRBUTTON = Body & %11111111 'Mask 8 bit
    IRDEVICE = (Body >>16) & %11111111 'Mask 8 bit

    If IRDEVICE=255 then goto start

    Serout ToCom ,N9600,[IRBUTTON] 'to PC COM - Port

    if IRBUTTON >=0 and IRBUTTON < 255 then
    high necLED
    pause 300
    low necLED
    endif

    pause 100
    goto start

    ' end of code for NEC OR that DVD REMOTE ----------------------------

    LED is blink for Both remote control. But Data in my PC software All keys are same number.

    How can I fix it.

    Thanks.

    Moe
    Attached Images Attached Images  
    Last edited by komoe01; - 30th August 2009 at 11:02.

Similar Threads

  1. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  2. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  3. Infrared Receiver
    By emavil in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th December 2006, 01:03
  4. how to get pic to pic communication
    By kinsiro in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th August 2005, 17:12
  5. Can this IR Xmitter/Rcvr be improved?
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th August 2005, 11:27

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts