Hello all,
I want briefly mention that I had similar code a long time ago.. but since Ivanrosale posted his I will give him the credit.
Its been a while since my last Article. This project was a long time coming for one of my home projects.
I have recently come across a bulk quantity of PIC16F628A in the SSOP package. if you are not familiar with the SSOP package the processor is about the size of your pinky fingernail.
This board was designed for the sole reason to turn on and off an RF switch. The RF lamp switch I acquired years ago was from radio shack and has long been discontinued. but any RF remote wall outlet has potential.
The Board features a Micrel 3.0 Amp adjustable voltage regulator (29302WU) and is set to 5Vdc Output and is also protected by a fuse. The Mini USB jack is not for usb but is ICSP. it allows the board to be programmed through my modified U2 programmer. Pic Kit 3 ICSP pin header was also added.
The PIC16F628A receives input to PORTA.2 from sparkfun Electronics IR Receiver Diode. The footprint for the Surface mount IR Receiver is also available in the same location on the board. The PIC's output drives a 7 bit Darlington array (ULN2003). the primary function for this is to close a switch to ground.
By setting any pin on PortB [5:0], PortA.1 to high will cause the output of the array to go to ground in turn lighting the corresponding LED attached to that output.
For this project the Radio shack uses a 12v battery for power. I tried powering the remote from this board but the RF chip requires 12v. Not a problem. I noticed the switches on this remote contact ground. Did i tell you that this board was designed around this remote. By attaching our outputs to both sides of the switches on the remote it basically acts as an extended switch. So instead of pushing the buttons on the remote the IR board is gonna do it. Just keep in mind that since the remote uses a battery a common ground between both systems is needed.
My modified code will learn the First IR code it receives and stores it as long as there is power. the reason for this is because, this is going into my theater room and want to turn off the lights with the button I dedicate. what better way than to learn the Button you want to use.
(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




Bookmarks