This is an adaptation of some code for NEC remotes that is on this forum. Up till now I've just been using it for decoding the leader pulse to enable a simple on/off switch and it works great, but now I want to use it for a specific keypress on my remote. The key will output 0xFF629D. (11111111 0110 0010 1001 1101).
I'm a bit confused on where and what is going to show up on each of the bytes when it sees the 0xFF629D --
ADDR '00000110 ?
ADDRINV '00000010 ?
COMM '00001001 ?
COMMINV '00001101 ?
probably have that all wrong thanks for any help on this. trying to save time -- didn't want to breadboard something.
was going to an IF byte = then high an led. but thought i'd just ask instead.
Code:
'12F508 nec REMOTE CONTROL RECEIVER (RENTRON)
#CONFIG
__config _OSC_IntRC & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
TRISIO = %000001 'GPIO.0 IS REMOTE RCVR INPUT, GPIO2 IS OUTPUT
DEFINE OSC 4
LEADERr VAR WORD ' will be up to 900 for a 9mS leader pulse
BTNVAL VAR BYTE[32] ' holds 32 pulse results
ADDR VAR BYTE ' address byte
ADDRINV VAR BYTE ' inverse of address byte
COMM VAR BYTE ' command byte
COMMINV VAR BYTE ' inverse of command byte
X VAR BYTE ' loop count
MAIN:
PULSIN GPIO.0,0,Leader ' leader pulse is ~9mS low-going
IF Leader < 850 THEN mAIN
FOR X = 0 TO 31 ' grab 32 incoming pulses
PULSIN GPIO.0,1,BtnVal(X) ' measuring high-going pulse widths
NEXT X
'we'll decode 4 bytes from 32 pulses....
FOR X = 0 TO 7 'FIRST 8 PULSES ADDRESS BYTE
IF BtnVal[X] > 150 THEN ' > 150 x 10uS = > 1.5mS pulse period
addr.0[X] = 1
ELSE
addr.0[X] = 0
ENDIF
NEXT X
FOR X = 8 TO 15 'SECOND 8 PULSES ADDRESS BYTE (INVERSE)
IF BtnVal[X] > 150 THEN
addrinv.0[X-8] = 1
ELSE
addrinv.0[X-8] = 0
ENDIF
NEXT X
FOR X = 16 TO 23 'THIRD 8 PULSES COMMAND BYTE
IF BtnVal[X] > 150 THEN
comm.0[X-16] = 1
ELSE
comm.0[X-16] = 0
ENDIF
NEXT X
FOR X = 24 TO 31 'FOURTH 8 PULSES COMMAND BYTE (INVERSE)
IF BtnVal[X] > 150 THEN
comminv.0[X-24] = 1
ELSE
comminv.0[X-24] = 0
ENDIF
NEXT X
PAUSE 1000
GOTO Main
Bookmarks