PDA

View Full Version : ir decode using pulsin help needed!!!



engineer7
- 23rd May 2011, 08:57
here is my code:


'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 5/23/2011 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
Define OSC 20
Header var word
Body var word
i var byte
tmp var Byte
irButton var byte
irDevice var byte
irIN var PortA.2
SonyLED var PortB.2

TrisA = %00000100
TrisB = 0
Start:
LOW SONYLED
IRBUTTON=255: IRDEVICE=255

Pulsin irin,0,header
if header > 1000 or header < 1350 then goto Start

for i =0 to 11
pulsin irin,0,tmp
if tmp >= 480 then
Body.0[i]=1 'Sony Logic 1 is 120
else
Body.0[i]=0 ' 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

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


i am using pic16f877a n i am definitely using picbasic pro now.
but the pin portb.2 never gets high on pushing any button of my sony remote.can anyone plz plz help me out with this.i really need to make it work plz!

Pimentel
- 23rd May 2011, 11:07
Engineer7,

You need to use a Sony control!
I use Sony IR protocol with sucess, and my rotine decode all key, then you only need to test the value and to do something...


@ DEVICE pic16F628a, INTRC_OSC_NOCLKOUT ' System Clock Options
@ DEVICE pic16F628a, WDT_OFF ' Watchdog Timer
@ DEVICE pic16F628a, PWRT_OFF ' Power-On Timer
@ DEVICE pic16F628a, BOD_OFF ' Brown-Out Detect
@ DEVICE pic16F628a, MCLR_ON ' Master Clear Options (External)
@ DEVICE pic16F628a, LVP_OFF ' Low-Voltage Programming
@ DEVICE pic16F628a, CPD_OFF ' Data Memory Code Protect
@ DEVICE pic16F628a, PROTECT_OFF ' Program Code Protection
DEFINE OSC 4
'Definição das variáveis e declarações
INCLUDE "bs1defs.bas" 'inclui arquivo p/ compatibilizar com BS1
'p/entender as variáveis b0...b3, w0...w6 e bit0...bit13
CMCON = 7 'DEFINE PORTA COMO DIGITAL (COMPARADORES ANALÓGICOS:OFF)
symbol ir = PORTB.7 'entrada do sinal de IR
SYMBOL LED = PORTB.4
SYMBOL RELE = PORTB.0
TRISB = %10000000
'------------------------------------------------------------------
'rotina principal
LOOP:
pulsin ir,0,w0 'aguarda start bit
if w0 < 200 then LOOP 'start bit é > 200
pause 20 'pula primeiro envio
pulsin ir,0,b0 'aguarda 2º start bit
pulsin ir,0,b1
pulsin ir,0,b2 'lê cada bit do código IR.
pulsin ir,0,b3
pulsin ir,0,b4
pulsin ir,0,b5
pulsin ir,0,b6
pulsin ir,0,b7

bit0=b1/96 'extrai LSB
bit1=b2/96
bit2=b3/96
bit3=b4/96
bit4=b5/96
bit5=b6/96
bit6=b7/96 'extrai MSB
bit7=0

if b0=21 then COMANDO
GOTO LOOP

COMANDO:
B0 = 0
RELE = 1
LED = 1
PAUSE 500
RELE = 0
LED = 0
GOTO LOOP

'----------------------------------------------------------------
end

mackrackit
- 23rd May 2011, 11:55
I can not help much on th decoding but there is a problem with your setup. PORT.A is analog so you will need to turn the ADC off.
http://www.picbasic.co.uk/forum/showthread.php?t=561

engineer7
- 25th May 2011, 05:21
sir i have gone through the link which you have given. but i cant seem to find the command for which to turn the ADC off. plz help in this regard.im using picbasic pro.
n secondly
if i take my sensor output to some other port lets portb.2 then i m guessing that there wont be any problem of ADC etc.?????

Ioannis
- 25th May 2011, 07:36
If I remeber right, your PIC has comparators and ADC. So, read for me the DS and find the appropriate registers to setup.

Alternatively use the include file from Darrel and get over with.

http://www.picbasic.co.uk/forum/showthread.php?t=11100&highlight=all_digital

Ioannis

engineer7
- 25th May 2011, 08:38
ok thanks a lot:)