MEL PICBASIC Forum - Add IR remote control capabilities to your next project!!

• ### Recent Forum Posts

#### Re: Doing something at predefined amount of steps?

Wasn’t it just something like this?
not even timing of course because every fifth iteration takes slightly longer to execute, but could be balanced up if it mattered.

variable var word...

Art Today, 15:30

#### Re: Doing something at predefined amount of steps?

I don't know for sure but since it involves division my guess is that this is slower. Speed isn't always everything though.

Tell you what, why don't you try both ways and measure the difference,...

HenrikOlsson Today, 15:01

#### Re: Doing something at predefined amount of steps?

Thanks! this is way better and simpler. Speaking speed-wise, will this be faster in execution than my code with additional variable?

CuriousOne Today, 14:42

#### Re: Newbie Manchester Coding question

Duh, yup, that was it [slapping forehead].

Cheers,

Troy

rocket_troy Today, 14:22

#### Re: Newbie Manchester Coding question

the DEBUG output is inverted logic to suit the pickit 2 serial input, your setup might req true logic
try
DEFINE DEBUG_MODE 0 ' Debug mode: 0 = True, 1 = Inverted

me too , i was...

richard Today, 13:03

#### Re: Newbie Manchester Coding question

Back... [and total exhausted]

Thanks sooo sooo much Richard and Dave (particularly Richard). I just ran Richard's code and as expected I got complete and utter nonsense - I have no luck in...

rocket_troy Today, 12:25

#### Re: Doing something at predefined amount of steps?

I think what you're looking for is the modulo operator (//).
It will return the remainder of a division so whenever it returns 0 it means it was an "even division".

MainCount = MainCount + 1...

HenrikOlsson Today, 12:17

#### Doing something at predefined amount of steps?

Hello and sorry for bogus title, I just can't explain it simpler in short terms :)

The idea is as follows, there is a variable, incremented from 1 to say 1000.

There is something to be done in...

CuriousOne Today, 07:35

#### Re: Newbie Manchester Coding question

Since i'm playing around with the simulator i stuck dave's code in for a look. first thing i noticed is that i made the simulated bit time twice as long as it should be

all three version "agree"...

richard Today, 06:17

#### Re: Complex math on 16F series?

This is polynomial interpolation, designed to smooth out camera slider movements. User enters 3 sets of X and Y data and then slider moves along these points. As long as input variables are in...

CuriousOne Yesterday, 20:54

Add IR remote control capabilities to your next project, easily, cheaply and effortless...
The code is somewhat crude, but it works flawlessly to me!

What do you need:
PIC12F675 (Or you can easily adapt the code to another one)
Photo IC Infrared 38KHz (you can use one from an old TV or VCR)
A cheap remote control compatible with Sony TV
That's it!

I found this keychains for less than \$2:

You can implement this code in two different ways, as a standalone project or to pass IR commands to another PIC in your main project (See the comments in the code)

Ok, enough talk, here is the code, the schematic is straightforward and it's included in the code:

Code:
```'****************************************************************
'*  Name    : SonyIR+12F675                                     *
'*  Author  : Ivan Rosales - Guadalajara, Jalisco, México       *
'*  Notice  : Copyright (c) 2011 Ivan Rosales                   *
'*  Date    : 01/09/2011                                        *
'*  Version : 1.0                                               *
'*  Notes   : GP0 (Pin 7) Salida Debug (Debug Exit)             *
'*          : GP3 (Pin 4) Entrada de Pulsos (Pulse Input)       *
'*                              __________                      *
'*          Vdd (5vdc)         | 16 Ch+   |                     *
'*            +                | 17 Ch-   |                     *
'*  PNA4612M  |                | 18 Vol+  |                     *
'*   .-----.  |                | 19 Vol-  |                     *
'*   | \  /|  |                | 20 Mute  |                     *
'*   |1/2\3|  |                | 21 Power |                     *
'*   'o-o-o'  |                | 54 Sleep |                     *
'*    | | |   |  PIC12F675     |__________|                     *
'*    | | |   |    ___                                          *
'*    | | '---o--o|º  |o---.                                    *
'*    | |       -o|   |o---)------> Debug Exit (RS232)          *
'*    | |       -o|   |o-  |                                    *
'*    '-)--------o|___|o-  |                                    *
'*      |                  |              600uS   600uS         *
'*      o------------------'       ________    ____    __       *
'*      |                         | Start  |__| 1  |__| 0|      *
'*     ===    Sony SIRC Signal:                                 *
'*     GND                          2.4mS      1.2mS  600uS     *
'*                                                              *
'* Note: If you can't find the PNA4612M use any TV IR Receiver, *
'* it's almost sure to work if it's in the 38KHz-40Khz range.   *
'*                                                              *
'* If you have troubles getting this thing to work, try adding  *
'* a 10K pullup to pin 4 and a .1uf cap between Vdd and Vss     *
'****************************************************************
@ Device PIC12F675,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_OFF,BOD_OFF
CMCON=7             'Don't use analog comparators
DEFINE OSCCAL_1K 1  'Internal Clock Auto-Cal

DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 0
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 0 'Mode: 0 = true, 1 = inverted

Pulse    var byte[12]
Start    var byte
Command  var byte
Device   var byte
Counter  var Byte

'The PULSIN resolution is 10uS with PIC running at 4MHz
WaitForStart:                       'Wait for Start signal
PuLSIN GPIO.3,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 GPIO.3,0,pulse[counter]
next

StoreBits:
command=0
device=0
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
'_________________________________________________________________________
'Use something like the code in this section for STANDALONE operation, or
'comment this section, send the commands to another PIC via Debug,
'and use DEBUGIN on the receiver PIC
select case command
case 16           'If Ch+ is pressed then turn On X
high GPIO.1
case 17           'If Ch- is pressed then turn Off X
low GPIO.1
case 18           'If Vol+ is pressed then turn On Y
high GPIO.2
case 19           'If Vol- is pressed then turn Off Y
low GPIO.2
case 21           'If Power is pressed then turn On Z
high GPIO.0
case 20,54        'If Mute or Sleep is pressed then turn Off Z
low GPIO.0
end select
'_________________________________________________________________________

'*************************************************************************
'Uncomment the next line to pass the commands to another PIC at 2400 Baud 8N1
'debug command
'*************************************************************************

pause 100             'Waste some time to ignore repeated commands
'(Sony SIRC sends at least 3 times the same command)
goto WaitForStart```
Enjoy!

Ivan.