I've done a few learning remotes. I can't give you all of it, but I can share a few little odds & ends you might find useful.
This simple routine allows you to output your carrier bursts on any pin that can be used as an output, and it's easy enough to modify for most any carrier frequency.
Note this assumes a 4MHz osc. Internal or external work equally well.
Code:
@ #define IRTX PORTC ; Define port to use for IR out
@ #define PIN 2 ; Define port pin to use for IR out
' Note: Be sure to make the above pin an output
TRISC.2 = 0
PORTC.2 = 0 ' LED off on boot
Cycles VAR BYTE ' Make sure this is always located in bank0
GOTO Main ' Jump over routine to main program entry point
Pulse: ' Generate "Cycles" number of 40kHz pulses
ASM
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bcf IRTX,PIN ; 1uS, LED=off
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
decfsz _Cycles,f ; + 1uS = 10S
goto _Pulse ; + 2uS = 12uS
return ; Return to caller
ENDASM
Using this is very easy. Load the number of carrier cycles into Cycles, then CALL Pulse.
If you need a carrier burst longer than 255, simply call Pulse again immediately after the 1st call. IR detectors are relatively slow in responding, so it's unlikely you'll see a break in the burst on the receiving end. I never have.
Can't share the larger routine with you, but this shows one simple approach to getting the IR output on any pin.
Making a learning remote isn't really all that hard, but it can be memory hungry depending on the width of carrier bursts, data packets, etc, the IR remote you're learning outputs.
Learning a single remote is much easier than a boat load of different brands.
TIP: Use PULSIN to read & store each logic 0 carrier burst width into an array. The first low pulse is normally a synch pulse, then data. Some remotes will include a long carrier burst period between each packet. That will vary from one mfg to another.
Run through a second PULSIN routine waiting for the logic 0 synch pulse, then start recording/storing the logic 1 periods.
These will be the periods where you PAUSEUS between loading Cycles & calling Pulse when recreating the outgoing data.
TIP #2: My first learning remote I made the user press a button until I had sorted all out logic 0 (carrier burst periods), then lit an LED telling the user to release the button. The same button was pressed once again, and it learned the logic 1 periods between carrier bursts by synching up with the initial logic 0 synch burst. Viola! Codes all learned & stored.
You end up with the whole data pattern, and it's pretty simple from there to re-create the same IR signal.
TIP #3: I eventually used a PIC where I could switch oscillator speeds on the fly, read in pulses at higher speeds for better resolution, then switched back down to the lower osc speed to send, and finally to the lowest speed and entered sleep for ultra low power use until a keypress. Worked really nifty.
Hope that helps. If you want a few more IR goodies contact me off-list. I can share a couple more routines with you if it's 100% for personal use.
Bookmarks