Dave thanks for the link as always.
For the record I have never wanted anyone, nor asked anyone to write code for me! I am not using PIC's nor electronics for any commercial gain ..it is merely a hobby !
I have asked only for code snippets to gain more of an understanding of certain aspects of a particular technology or to move past a struggling block.
So THANK YOU to you and to all the others who still reply no matter how many times they have heard and answered the same questions.
It's fantastic that so many here are happy to share code and experiences with others but please understand that as simple as it may seem for some to read and understand, it may take others lifetimes and that's where a few lines in a reply to a question will advance the learning process.
To err is human ... not so ?
So off I went
Forums,sites,articles, google,the manual, late nights, Dave's suggestions, Bruce's site, and Les Johnson's article oh yes and dome app note from microchip, and many cups of coffee.... I am slowly moving closer to some sort of understanding (or more confusion)....
See, the big problem was trying to grasp the PULSIN command and the resolutions @ given oscillator rates which LES JOHNSON does extremely well in the article "Controlling the world from your armchair" , in the article Les says
Well that certainly did start clearing up the a lot confusion I have had with the PULSIN command for so long, it is still a little confusing for me I must admit ..stupid human that I am !I hope that I’ve succeeded in illustrating
that both, infrared decoding and
PICmicro programming need not be the
exclusive property of the whizz kids or
rocket scientists among us.
Anyway , with enough bashing away and peeking and poking I finally came up with something that seems to work , but only with a certain remote code typed into a universal remote. At the moment there must be at least 12 different remote controls scattered around the workbench.
Here is the code :
The code behaves differently for most remotes and I'm sure only very well for those sending RC5 codes.Code:' Philips RC5 IR decoder for 12F629 @ 4MHZ 'set for samsung TV on universal rae-1000 (or similar??) remote - TV1 -code 189 most buttons work define OSC 4 '4MHz DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1k -HELPS tuning the crystal for more accurate timing CMCON = 7 'TRISIO = %76543210 ' port GPIO 0=output and 1=input TRISIO = %00000010 ' GPIO.1 is an input all the rest are outputs 'OPTION_REG.7 = 0 ' Internal pull-ups = on 'debug defines DEFINE DEBUG_MODE 0 ' Debug sending INVERTED serial data DEFINE DEBUG_REG GPIO ' Debug Port = GPIO DEFINE DEBUG_BIT 2 ' Debug.bit = GPIO.2 DEFINE DEBUG_BAUD 2400 ' Default baud rate = 2400 'end of debug defines 'Variables begin here RC5CODE VAR WORD ' Holds 12-bit RC5 code CYCLEX VAR BYTE ' used to hold the loop count for bit collection IRPIN VAR GPIO.1 ' GPIO.1 input pin reading data 'end of variables main: 'check for a valid header IF IRPIN = 1 THEN main 'Only start when PULSE is a LOW PAUSEUS 100 'Pause for 0.1mS IF IRPIN = 1 THEN main 'Could be junk so try again PAUSEUS 1350 'Pause for 1.350mS 'header check is good so now continue rc5code.0[13] = IRPIN 'Setup array to read each pulse into Bits FOR CYCLEX = 12 to 0 STEP - 1 'read 13 Pulses/bits in reverse order RC5CODE.0[cyclex] = IRPIN 'build the array PAUSEUS 1800 ' PAUSE 1.8mS then start reading next BIT/pulse NEXT cyclex 'go back and do it again IF RC5CODE.LOWBYTE = $FF THEN main 'Check to see if it's junk we received $FF aka 255 'OK now dow some AND-ing/bit-masking to get the codes right RC5CODE = ~RC5CODE & $003F ' Mask upper 10-bits to return 6-bit data ' in lower 6-bits of word result 'Send it to the MAX232 or serial port for display debug "Key Pressed = ",DEC rc5code ' send the code to serial port/MAX @ 2400bps TRUE 'for LCDOUT ALTER THE NEXT LINE 'LCDOUT "kepress is", DEC RC5CODE RC5CODE=0 ' Clear the variable for next keypress PAUSE 500 ' a short DEBOUNCE -If you leave this out then expect duplicates -- ! GOTO main 'start again from main end
Will post the circuit later on ..really simple but it works.
I am busy playing around with Les Johnson's code (what I could make out in the article) and will post that later on too.
Dave .. I will keep bashing away and post progress.
Keep well
Kind regards
Dennis
Bookmarks