Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

control few relays via infrared remote control

Status
Not open for further replies.
Below is my RC-5 decoding code for PIC16F84A.
PHP:
/*TARGET MICROCONTROLLER -PIC16F84A*/
/*COMPILER - High Tech C                        */

#include <pic.h>
#define _XTAL_FREQ 4e6
#define us __delay_us
#define ms __delay_ms
unsigned char buf,flag;
__CONFIG(0x3FFA);
void interrupt RC5() //RC5 decoding inside ISR
{	
INTF=0;
if(RB0==0)
{
us(100);
if(RB0==0)
	{
	us(100);
	if(RB0==0)
		{
		us(889);
		if(RB0==1)
			{
			us(889);
			if(RB0==0)
				{
				ms(10.632);
				buf=0;
				for(int a=0;a<6;a++)
					{
					buf<<=1;
					if(RB0==1)
						{
						buf++;
						}
					ms(1.778);
					}
				
				buf&=0b00111111; /*SIX COMMAND BITS EXTRACTED*/
				flag=1;
				RA3=1;ms(30);RA3=0;
				}
			}
		}
	}
}

}



main()
{
__delay_ms(50);
__delay_ms(100);
__delay_ms(50);
PORTB=0;	
PORTA=0;
TRISB=1;	//To make RB0 as input 
TRISA=0;
GIE=1;		//Global interrupt enable
INTE=1;		//RB0 interrupt enable
INTEDG=0;	//Interrupt on High to Low transition 

while(1)
	{
	flag=0;
	if(buf==0){RB1=~RB1;}
	else if(buf==1){RB2=~RB2;}
    else if(buf==2){RB3=~RB3;}
    else if(buf==3){RB4=~RB4;}
    else if(buf==4){RB5=~RB5;}
    else if(buf==5){RB6=~RB6;}
    else if(buf==6){RB7=~RB7;}
    else if(buf==7){RA0=~RA0;}
    else if(buf==8){RA1=~RA1;}
    else if(buf==9){RA2=~RA2;}
   	flag=0;
	while(flag==0);
	}
}
But you can use it in any PIC by small modifications...
You can control it using a PHILIPS TV remote (RC5 protocol). But i think almost all philips TV remote follows this protocol.
You can use any IR remote working with RC-5 protocol because the program only detects the 6 command bits and all others are ignored.
I didn't included a PWM in this because at the time when i coded this, my aim was just to decode RC5 signal. More over, PIC16F84A doesn't have PWM module, but a software PWM is possible...
Now, you can include more devices by understanding the 6bit command for each key in a Philips TV remote, so that you can select any key for PWM. You can learn more about Philips RC5 protocol from below link.
SB-Projects: IR Remote Control, Philips RC-5 Protocol

---------- Post added at 10:27 ---------- Previous post was at 10:09 ----------

TSOP output is to be connected to RB0.

---------- Post added at 10:33 ---------- Previous post was at 10:27 ----------

---------- Post added at 10:46 ---------- Previous post was at 10:33 ----------

 
Last edited:

Below is my RC-5 decoding code for PIC16F84A.
PHP:
/*TARGET MICROCONTROLLER -PIC16F84A*/
/*COMPILER - High Tech C                        */

#include <pic.h>
#define _XTAL_FREQ 4e6
#define us __delay_us
#define ms __delay_ms
unsigned char buf,flag;
__CONFIG(0x3FFA);
void interrupt RC5() //RC5 decoding inside ISR
{	
INTF=0;
if(RB0==0)
{
us(100);
if(RB0==0)
	{
	us(100);
	if(RB0==0)
		{
		us(889);
		if(RB0==1)
			{
			us(889);
			if(RB0==0)
				{
				ms(10.632);
				buf=0;
				for(int a=0;a<6;a++)
					{
					buf<<=1;
					if(RB0==1)
						{
						buf++;
						}
					ms(1.778);
					}
				
				buf&=0b00111111; /*SIX COMMAND BITS EXTRACTED*/
				flag=1;
				RA3=1;ms(30);RA3=0;
				}
			}
		}
	}
}

}



main()
{
__delay_ms(50);
__delay_ms(100);
__delay_ms(50);
PORTB=0;	
PORTA=0;
TRISB=1;	//To make RB0 as input 
TRISA=0;
GIE=1;		//Global interrupt enable
INTE=1;		//RB0 interrupt enable
INTEDG=0;	//Interrupt on High to Low transition 

while(1)
	{
	flag=0;
	if(buf==0){RB1=~RB1;}
	else if(buf==1){RB2=~RB2;}
    else if(buf==2){RB3=~RB3;}
    else if(buf==3){RB4=~RB4;}
    else if(buf==4){RB5=~RB5;}
    else if(buf==5){RB6=~RB6;}
    else if(buf==6){RB7=~RB7;}
    else if(buf==7){RA0=~RA0;}
    else if(buf==8){RA1=~RA1;}
    else if(buf==9){RA2=~RA2;}
   	flag=0;
	while(flag==0);
	}
}
i want to use 16f676 with LG tv remote (RC5 protocol , add value + 1 , command value =
1to 8 ). so pl guide me how can change it with Ur code...
 
Last edited:

hello, actually if you understood the above code, then you can easily solve your problem...
So you can ask if you have any doubt in above program...

Actually in the code above, the RC5 decoding is done inside ISR. In your pic the external interrupt pin is not RB0. Then you may pls check the datasheet of your pic and make required change...

Any way, before trying for modification, just try to understand the code, then, i am sure you could modify it yourself, if you have the datasheet of your pic..
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top