be80be
Well-Known Member
Pic basic pro has pulsin command that can count pulses. Like from remote controllers. Atom did some code for the sony remote He used delays to time how fast it checked for change in state.
So I tried this code i made and it look like it is catching the code. I just wanted some thoughts about it. Thanks
It will run on the junebug it blinks led1 and 6 as output.
So I tried this code i made and it look like it is catching the code. I just wanted some thoughts about it. Thanks
Code:
{
*****************************************************************************
* Name : IRsony.bas *
* Author : burt ratliff *
* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 6/9/2009 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F1320
Clock = 8 // tells the compiler the FOSC speed
Config OSC = INTIO2, WDT = OFF, LVP = OFF, MCLRE = OFF
Include "Utils.bas"
Include "INTOSC8.bas"
Dim IrIn As PORTB.0
Dim led As PORTA.0
Dim IrTime As Byte
dim code as word
SetAllDigital
TRISB =%00000001
PORTB =%00000000
TRISA =%00000000
PORTA =%00000000
IrTime = 0
While true
IrIn =0 //sets IRmodule to low
Repeat
IrIn = 1 //makes sure we start high
Until IrIn = 0 // If low we are at start of a pulse
Repeat IrIn = 0 //repeats till the end of the start pulse
DelayUS(200)
Inc (IrTime)
Until IrTime >= 10 //make sure its start is2.4mS
If IrTime >= 10 Then
EndIf
IrTime = 0 // reset to get code
repeat
if IrIn =0 then // checks for 0
delayus(200)
Inc (IrTime) //
endif
until IrTime >= 3 //checks to see if it is .600mS long
repeat
If IrIn = 1 and IrTime >=3 then //
code = 0 // writes to code a 0
elseif IrIn =0 and IrTime >=3 then // checks for a 1
delayus(200)
inc (IrTime)
endif
until IrTime >=6 //makes sure it's 1.2mS
if IrIn =1 and IrTime >=6 then
code =1 // writes to code a 1
endif
porta.0 = code // just outputting to led to see how it working
Wend
End
Last edited: