IR – Decoder for Sony Remotes

Sunday, January 13, 2008

Infrared remote control has been around for a very long time now, and we tend to take it for granted. Yet, it is a marvel of modern technology, which allows a whole variety of devices to be activated with the touch of a button. Remote control handsets are so abundant that they may be purchased new for a few pounds, which makes them viable items for experimentation. There are dedicated chips available that will decode the signals from a particular handset, however, with the flexibility and cost effectiveness of the PIC range of microcontrollers we can develop a decoding subroutine that may be placed into your own programs, or used as a standalone infrared to RS232 converter.

It is not my intention to teach you how to program a PICmicro, therefore, throughout this article; it is assumed that you already have some knowledge of either assembler or PicBASIC Pro. And that you have a means of programming the PIC16F84. For more information concerning the PicBASIC range of compilers, as well as an assortment of programmers, visit Crownhill Associate’s dedicated web site at www.picbasic.co.uk. For information concerning assembler programming, visit Microchip’s web site at www.microchip.com.

Here is the circuit diagram. I successfully built this.



The out put of RS232 is like this

IR_BUT<Button Code>\rIR_DEV<Device Code>\r

Button Code is the value assigned to the button i.e E00(in hex) is the value for for Number 1 button
Device code is the value assigned to the device.

Source Code written is PICBasic

'****************************************************************
'* Name : Sony_ir.BAS
'* Author : K.C. Hewage
'* Date : 2/1/2007
'* Version : 1.0
'* Notes :
'****************************************************************

Include "modedefs.bas"

DEFINE OSC 4

'*******Alias************

Red_Led var PORTA.0
Green_Led var PORTA.1
IR_Sense var PORTA.2
Serial_out var PORTA.3

'*******Variables************

IR_Dev var byte
IR_But var byte
ST var word
IR_Word var st
BitCnt var byte
ID var byte
IR_Valid var bit


Serout Serial_out,N9600,["My IR Device",13]
Serout Serial_out,N9600,["Hello",13]


Main:

low red_led
low green_led

gosub irin

If IR_Valid = 1 then

high red_led
pause 200
low red_led

Serout PortA.3,N9600,["IR_BUT", ir_but, 13, "IR_DEV", IR_dev, 13]

endif

goto main

IRIN:

IR_Valid = 1

pulsin IR_Sense, 0, st

If st < ir_valid =" 0"> 270 then IR_Valid = 0 : Return' If not valid then exit

ir_word = 0
ID = 0
ir_but = 0
ir_dev = 0

For Bitcnt=0 to 11 ' Create a loop of 12
Pulsin ir_sense,0,Id ' Receive the IR bit pulse

If id >= 90 then ' If it's >= 90 then we've received a 1
ir_word.0[bitcnt] = 1
else
ir_word.0[bitcnt] = 0
endif

Next ' Close the loop

ir_but = ir_word & %01111111
ir_dev = 011111 & (ir_word >> 7)

return




Posted by K.C. Hewage at 1:13 AM