Hi Naga,
I did some RC5 controlled projects last year.
I did some searching but i could only find some of my test code.
You should read the info found on http://www.sbprojects.com/knowledge/ir/rc5.htm this will give you an idea of how it works and a schematic ...
Best regards, UB
Code:'==== Set fuses ========================= @ device pic10F202,wdt_off,mclr_off,protect_off '==== Set XTAL ========================= DEFINE OSC 4 ' int XTAL @ 4 Mhz '==== Set variables ====================== Y VAR word ' To Hold the 12-bit RC5 code TMP var BYTE '==== Set IO =========================== IR_PIN VAR GPIO.3 ' GPIO.0 input pin reading IR data SDA var GPIO.0 SCL var GPIO.1 'errled var GPIO.2 OPTION_REG.7 = 0 ' Internal pull-ups = on TRISIO = %00001000 ' Set TRIS register input's & output's OPTION_REG.5 = 0 ' Set Timer inc. on internal inst. GPIO = %00000000 ' Set all digital low '==== Signal information ================== 'Given the information found on http://www.sbprojects.com/knowledge/ir/rc5.htm ' 'bit 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ' | | | | | | | | | | | | | | | 'uSec 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 '==== Main program ====================== MAIN: IF IR_PIN = 1 THEN GOTO MAIN ' Wait for the first bit to arive y.13 = IR_PIN ' Incoming signal pauseus 889 ' In order to see this 0 we are in the second ' period of the first 1.778 msec, so we will ' wait another 889 usec to enter the 2nd period. pauseus 1600 ' Almost at the end of the second period, look for y.12 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.11 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.10 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.9 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.8 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.7 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.6 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.5 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.4 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.3 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.2 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.1 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period pauseus 1600 ' Almost at the end of this period, look for y.0 = IR_pin ' a high or low signal pauseus 178 ' Time to the end of this period y = ~y ' Invert y word if Y.lowbyte = 255 then goto ERROR ' If all lowbytes are 0xFF then noise is received TMP.1 = Y.13 TMP.0 = Y.12 if not tmp = 3 then goto error TMP.4 = Y.10 TMP.3 = Y.9 TMP.2 = Y.8 TMP.1 = Y.7 TMP.0 = Y.6 if not tmp = 0 then goto error TMP.2 = Y.5 TMP.1 = Y.4 TMP.0 = Y.3 if tmp > 0 then goto error TMP.2 = Y.2 TMP.1 = Y.1 TMP.0 = Y.0 ' TMP now holds the decoded RC5 signal '==== End of main loop reset and go from top ==== ERROR: Y=0 tmp=0 ' Clear key codes PAUSE 250 ' debounce GOTO MAIN ' Return to main loop END




Bookmarks