Code:
'==== Set fuses ================================================================
@ device pic10F202,wdt_off,mclr_off,protect_off
'==== Set includes =============================================================
INCLUDE "modedefs.bas" ' Include for Serout
'==== Set XTAL =================================================================
DEFINE OSC 4 ' int XTAL @ 4 Mhz
'==== Set variables ============================================================
Y VAR word ' To Hold the 12-bit RC5 code
'==== Set IO ===================================================================
IR_PIN VAR GPIO.0 ' GPIO.0 input pin reading IR data
SERIAL var GPIO.1 ' GPIO.1 SEROUT 9600-8-n-1 output
TRISIO = %00001001 ' Set TRIS register input's & output's
OPTION_REG.7 = 0 ' Internal pull-ups = on
'==== Signal information =======================================================
'Given the information found on http://www.sbprojects.com/knowledge/ir/rc5.htm
'The incoming RC5 signal will look like this :
'
'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 se 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
'==== DEBUG , output received data serial ======================================
Serout serial,T9600,["STX= ",#y.13,#Y.12,#Y.11,10,13]
Serout serial,T9600,["SYS= ",#y.10,#y.9,#y.8,#y.7,#y.6,13,10]
Serout serial,T9600,["CMD= ",#Y.5,#y.4,#y.3,#y.2,#y.1,#Y.0,13,10]
'==== End of main loop reset and look again ====================================
ERROR:
Y=0 ' Clear key codes
PAUSE 250 ' debounce
GOTO MAIN ' Return to main loop
My problem now is:
Bookmarks