PIC Beginner - Infrared Receiver and IR Protocol
I'm a beginner for PIC Basic Program. I want to control my PC Program with IR Remote Control. In my place, we can get various IR remote control but a few type of PIC : 16F84A, 16F628A, 16F648A, 16F877A and 18F4550 can available.
I use 16F84A and 4MHz Crystal, RS232 for IR Remote Control.
My first program is IR Remote Receiver with Sony IR Protocol. I choose a DVD Remote Control (Made in China). I tested my receiver to my PC via COM port. It did not work. So I choose universal remote control and assign SONY. Now It's ok.
Secondly, I write my program with RC-5 Protocol. This code is posted by Bruce (http://www.picbasic.co.uk/forum/arch...php/t-308.html) It's also ok for universal remote that assigned for Philips. But it don't work for that DVD Remote Control.
Then I tested simply that DVD Remote Control's IR signal with LED. LED is worked between 900ms and 920 ms. It may be Header of IR train. I searched data of all protocols (http://www.sbprojects.com/knowledge/ir/ir.htm). I thought that DVD remote use NEC protocol. I also found that most of China DVD player's remote control use NEC IR protocol in a manual of DVD Player.
I learn NEC IR Protocol. It's type is different for Sony Protocol. Sony use Pulse Width Modulation [PWM]. But NEC use Pulse Distance Modulation [PDM]. I think that PulsIn is use to measure the pulse width. Is it right? So what is use to measure the distance between pulse. Is it [PulsIn + PAUSEUS]?
For NEC Protocol, I refer dhouston's post (http://www.picbasic.co.uk/forum/show...7859#post77859). My receiver's LED is ok for that DVD remote any key press but in my PC program all signal is Zero.
Any help would be greatly appreciated.
If this receiver is ok, I want to do Universal Infrared Receiver (UIR) with USB (with ref: eg. A universal algorithm for implementing an infrared decoder: www.edn.com/article/CA6653644.html.
Regard
Moe
1 Attachment(s)
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
Two IR Protocol in one PIC
I changed pin assign.
The result is successfully done.
I test ten different kind of DVD Remote. Key positions are changed but all are work well.
Now I run my program for two different tasks using same key of two different remote (Sony and NEC Protocol).
** two ir protocol can use in same pic **
Adouston,
THANK YOU VERY MUCH for your kindly help.
I read NEC protocol and compare code.
Header is 9ms
- no header found, restart
Quote:
If (stx<760) Then init
Space between header and body is 4.5ms
-wait space
Quote:
While PortA.2=1:Wend
Each pulse is a 560µs long
A logical "1" takes 2.25ms to transmit (pulse 560µs + space )
a logical "0" is only half of that, being 1.125ms (pulse 560µs + space )
Please let me know:
1. How to calculate (pulse>100) is logic 1.
2. and PULSIN_MAX 1140 . why do you use 1140
I say again. Thanks.
Moe.
Re: PIC Beginner - Infrared Receiver and IR Protocol
dears ,
i know its a very long time , but please am stick on this , can you post a full working code for pic16f84a to decode nec protocol .
many many thanks .