/**********************************************************************
* Phillips RC5 Decoding
*
* Author: Ajay Bhargav
* Description: This software is for Phillips RC-5 remote
* decoding. Pin used for reception is P3.3 while
* you can use any pin as per your requiremnet.
* This program is written for 8051 MCU running
* at 11.0592MHz.
*
* Usage: After the decoding the Address is stored in the
* ADDR variable and command is stored in the CMD.
* The flip bit is also stored to check whether the
* button is pressed once or not.
*
*
* Having a Doubts? Please post at
* [url=https://www.8051projects.net/forum.html]Forum : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes[/url]
*
**********************************************************************/
VAR1 equ r7 ;Temporary Variable
TEMP equ 10H ;Temp variable
COUNT equ 11H ;Count
ADDR equ 12H ;Device address
CMD equ 13H ;Command
FLIP bit 00H ;Flip bit
TOG bit 01H ;Temp bit for flip
IR equ P3.3 ;IR Receiver connected to this pin
org 00H ;Start of prog
mov sp,#50H ;Stack pointer initialization
clr TOG ;Clear temp bit
main:
jb IR,$ ;Wait for first bit
mov VAR1,#255 ;3.024mS delay
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#100
djnz VAR1,$
mov c,IR ;Read Flip bit
mov FLIP,c
clr A
mov COUNT,#5 ;Count for address
fadd:
mov VAR1,#255 ;1.728mS delay for each bit
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#4
djnz VAR1,$
mov c,IR
rlc a
djnz COUNT,fadd
mov ADDR,A ;Save the address
clr a
mov COUNT,#6 ;Count for Command
fcmd:
mov VAR1,#255 ;1.728mS Delay for each bit
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#4
djnz VAR1,$
mov c,IR
rlc a
djnz COUNT,fcmd
mov TEMP,CMD ;Save the old command
mov CMD,a ;Save the new command
mov a,ADDR ;Cheack for valid address
cjne a,#00,nvalid
mov a,TEMP
cjne a,CMD,valid ;Check for valid command
nvalid:
ljmp main
valid: ;Key press check
clr a
mov c,FLIP
rlc a
mov TEMP,a
clr a
mov c,TOG
rlc a
cjne a,TEMP,valid1
sjmp nvalid
valid1:
mov c,FLIP
mov TOG,c
mov a,CMD
clr c
/*--------------------
Your code goes here...
CMD contains the current command!
Just need to compare.. :)
----------------------*/
END ;End of program