Home Theater IR Remote Light Switch
- December 22nd, 2011
- Posted in Pic Micros
- Write comment
(the project case is a travel soap container.. LOL)
Code:
define osc 20
CMCON = 7
low porta.4
low portb.3
low portb.2
high porta.3
Pulse var byte[12]
Command var byte
Start var byte
Stored var byte
Device var byte
Counter var Byte
Compare1 var byte
Compare2 var byte
LampStatus var byte
X var byte
'*********************** Receive IR Signal *************************************
'The PULSIN resolution is 2uS with PIC running at 20MHz
WaitForStart: 'Wait for Start signal
PuLSIN PORTA.2,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 PORTA.2,0,pulse[counter]
next
if stored = 1 then Verify 'Check to see if any signal has been received.
'********************** Learn First IR Signal **********************************
StoreBits:
command = 0
device = 0
low porta.3
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
stored = 1
goto waitforstart
'********************** Compare to Stored IR signal ****************************
Verify:
compare1 = 0
compare2 = 0
for counter = 0 to 6
if pulse[counter] < 90 then 'Determine if the pulse represents 0 or 1
compare1.0[counter] = 0 'Storing new signal in Compare variable.
Else
compare1.0[counter] = 1
endif
next
for counter=7 to 11
if pulse[counter] < 90 then
compare2.0[counter-7] = 0
Else
compare2.0[counter-7] = 1
endif
next
for counter = 0 to 6 ' Compare incoming signal to the stored signal
if compare1.0[counter] <> command.0[counter] then Bad_signal
next
for counter = 7 to 11
if compare2.0[counter - 7] <> device.0[counter - 7] then bad_signal
next
GoodSignal:
if LampStatus = 1 then LampOff ' Check the Lamp Status
LampOn:
high portb.3
pause 1000
low portb.3
pause 3000
Lampstatus = 1 ' Set the lamp Status to 1 stating the lamp is on.
goto waitforstart
LampOff: 'Lamp Control
High portb.2
pause 1000
low portb.2
pause 3000
Lampstatus = 0
goto waitforstart
Bad_Signal 'Flash the Front LED for bad signal received. This my get annoying
for x = 0 to 10
pulsout porta.3,20000
pause 750
low porta.3
next
goto waitforstart

No comments yet.