• Add IR remote control capabilities to your next project!!

    Add IR remote control capabilities to your next project, easily, cheaply and effortless...
    The code is somewhat crude, but it works flawlessly to me!

    What do you need:
    PIC12F675 (Or you can easily adapt the code to another one)
    Photo IC Infrared 38KHz (you can use one from an old TV or VCR)
    A cheap remote control compatible with Sony TV
    That's it!

    I found this keychains for less than $2:


    You can implement this code in two different ways, as a standalone project or to pass IR commands to another PIC in your main project (See the comments in the code)

    Ok, enough talk, here is the code, the schematic is straightforward and it's included in the code:

    Code:
    '****************************************************************
    '*  Name    : SonyIR+12F675                                     *
    '*  Author  : Ivan Rosales - Guadalajara, Jalisco, México       *
    '*  Notice  : Copyright (c) 2011 Ivan Rosales                   *
    '*          : All Rights Reserved                               *
    '*  Date    : 01/09/2011                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : GP0 (Pin 7) Salida Debug (Debug Exit)             *
    '*          : GP3 (Pin 4) Entrada de Pulsos (Pulse Input)       *
    '*                              __________                      *
    '*          Vdd (5vdc)         | 16 Ch+   |                     *
    '*            +                | 17 Ch-   |                     *
    '*  PNA4612M  |                | 18 Vol+  |                     *
    '*   .-----.  |                | 19 Vol-  |                     *
    '*   | \  /|  |                | 20 Mute  |                     *
    '*   |1/2\3|  |                | 21 Power |                     *
    '*   'o-o-o'  |                | 54 Sleep |                     *
    '*    | | |   |  PIC12F675     |__________|                     *
    '*    | | |   |    ___                                          *
    '*    | | '---o--o|º  |o---.                                    *
    '*    | |       -o|   |o---)------> Debug Exit (RS232)          *
    '*    | |       -o|   |o-  |                                    *
    '*    '-)--------o|___|o-  |                                    *
    '*      |                  |              600uS   600uS         *
    '*      o------------------'       ________    ____    __       *
    '*      |                         | Start  |__| 1  |__| 0|      *
    '*     ===    Sony SIRC Signal:                                 *
    '*     GND                          2.4mS      1.2mS  600uS     *
    '*                                                              *
    '* Note: If you can't find the PNA4612M use any TV IR Receiver, *
    '* it's almost sure to work if it's in the 38KHz-40Khz range.   *
    '*                                                              *
    '* If you have troubles getting this thing to work, try adding  *
    '* a 10K pullup to pin 4 and a .1uf cap between Vdd and Vss     *
    '****************************************************************
    @ Device PIC12F675,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF
    ANSEL=0             'Don't use ADC's
    CMCON=7             'Don't use analog comparators
    DEFINE OSCCAL_1K 1  'Internal Clock Auto-Cal 
    
    DEFINE DEBUG_REG GPIO
    DEFINE DEBUG_BIT 0
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 0 'Mode: 0 = true, 1 = inverted
    
    Pulse    var byte[12]
    Start    var byte
    Command  var byte
    Device   var byte
    Counter  var Byte
    
    'The PULSIN resolution is 10uS with PIC running at 4MHz
    WaitForStart:                       'Wait for Start signal
    PuLSIN GPIO.3,0,start               'Check the low pulse width
    if start < 180 then WaitForStart    'If the Start pulse < 1.8mS repeat the loop
    
    for counter=0 to 11                 'Get the 12 pulses of the signal
        pulsin GPIO.3,0,pulse[counter]
    next 
    
    StoreBits: 
    command=0
    device=0
    for counter=0 to 6
        if pulse[counter] < 90 then     'Determine if the pulse represents 0 or 1
           command.0[counter] = 0       
        Else    
           command.0[counter] = 1
        endif
    next
    for counter=7 to 11
        if pulse[counter] < 90 then
           device.0[counter-7] = 0 
        Else    
           device.0[counter-7] = 1
        endif
    next
    '_________________________________________________________________________
    'Use something like the code in this section for STANDALONE operation, or
    'comment this section, send the commands to another PIC via Debug,
    'and use DEBUGIN on the receiver PIC
    select case command
        case 16           'If Ch+ is pressed then turn On X
             high GPIO.1
        case 17           'If Ch- is pressed then turn Off X
             low GPIO.1   
        case 18           'If Vol+ is pressed then turn On Y
             high GPIO.2
        case 19           'If Vol- is pressed then turn Off Y
             low GPIO.2
        case 21           'If Power is pressed then turn On Z
             high GPIO.0
        case 20,54        'If Mute or Sleep is pressed then turn Off Z
             low GPIO.0
    end select
    '_________________________________________________________________________
    
    '*************************************************************************
    'Uncomment the next line to pass the commands to another PIC at 2400 Baud 8N1
    'debug command
    '*************************************************************************
    
    pause 100             'Waste some time to ignore repeated commands
                          '(Sony SIRC sends at least 3 times the same command)
    goto WaitForStart
    Enjoy!

    Ivan.
    This article was originally published in forum thread: Add IR remote control capabilities to your next project!! started by ivanrosales View original post