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.

PIC16F877A NEC decoder in Hi-tech C compiler

Status
Not open for further replies.

jpsganesh

Full Member level 3
Full Member level 3
Joined
Aug 17, 2009
Messages
175
Helped
22
Reputation
44
Reaction score
21
Trophy points
1,298
Location
India
Visit site
Activity points
2,286
Dear all,

I'm trying to decode NEC IR remote with PIC16F877A uC. I'm using Hi-tech C compiler in MPLAB IDE.
I have connected IR Sensor signal I/P to RB0 (EXT INT) pin.
Finally Decoded IR code should be stored in some variable.
Can someone pls share the code in Hi-tech C compiler compatible.

Thanks in advance.
 

Thanks irfan, but I'm looking for program. I'm not strong in Programming can u share the code to decode the NEC in Hi-tech C.
 

i am also working on remote,s and also i dont use hi tech c compiler .
i use ccs compiler
i am not able to write 100% efficent code.
that's why i was not posting my code .
any way i am posting my code. maybe it will help you
//////////////////////////////////////////////////////////////////
Code:
//            SENSOR GIVES LOGIC 1 AT NO ACTIVITY   
////////////////////initialization//////////////////
#include  "16f877a.h"
#org 0x1F00, 0x1FFF void loader16F877a(void) {} //protect bootloader code for the 8k 16F876/7

#fuses    nowdt,noput,nobrownout
#use      delay(clock=4000000)
////////////////////////////////////////////////////
#byte  port_a = 0x05
#byte  port_b = 0x06
#byte  port_c = 0x07
#byte  port_d = 0x08
#bit   ir=port_a.1
#bit   led1=port_b.0
#bit   led2=port_b.1
#bit   led3=port_b.2
#bit   led4=port_b.3
#bit   led5=port_b.4
#bit   led6=port_b.5
#bit   led7=port_b.6
#bit   led8=port_b.7
#bit   led9=port_d.5
#bit  led10=port_d.4

/////////////////////////////////////////////////////\
char   i,command,data;
int1   x;
////////////////////////////////////////////////////
char   read_ir       (void);
int1   process_ir_bit(void);

////////////////////////////////////////////////
void  main  (void)

{
   
set_tris_d(0x00);   
set_tris_b(0x00);
port_b=0xff;
port_d=(0b00110000);
for(;;)
{
command=0x00;
while(ir==1);//start bit
while(ir==0);//start bit
while(ir==1);//start bit
for(i=0;i<16;i++)
{
  while(ir==0);//address
  while(ir==1);//address
}
///////////////command////////////////////////////////////
 for(i=0;i<8;i++)
 {
  x=process_ir_bit();
  if(x)  {bit_Set(command,i);  while(ir);while(ir==0);}
  else   {bit_clear(command,i);while(ir==0);}
  }
////////////////data///////////////////////////////////////// 
 for(i=0;i<8;i++)
 {
  x=process_ir_bit();
  if(x)  {bit_Set(data,i);  while(ir);while(ir==0);}
  else   {bit_clear(data,i);while(ir==0);}
  }
//////////////////////////////////////////////////////////////  
      if(data==03) led1=~led1;
 else  if(data==07)  led2=~led2;  
  else  if(data==11)  led3=~led3; 
   else  if(data==15)  led4=~led4; 
    else  if(data==19)  led5=~led5; 
     else  if(data==23)  led6=~led6; 
      else  if(data==27)  led7=~led7; 
       else  if(data==31)  led8=~led8; 
        else  if(data==35)  led9=~led9; 
         else  if(data==39)  led10=~led10;
          else  delay_ms(500);
          delay_ms(100);
}
}
  
  
/////////////////////////////////////////////////////////
int1   process_ir_bit(void)
{
delay_us(300);
delay_us(560);
if(ir)   return 1;
else     return 0;

}
///////////
 

I tried this. It's not working. I tried after modifying the logic. Still it's not working. This method will count when repeat pulse comes. Can you suggest some other technique pls.
 

the input signal is inverted as compare to nec standard because
ir receiver inverts the input signal.
so code is some different.

erase this line and compile the software (this line uses for bootloader in ccs compiler)
#org 0x1F00, 0x1FFF void loader16F877a(void) {}


after compiling varify the code on hardware.
 

I changed entire logic which will not read repeat pulse and will not get hang in while loop and along with EXT INT RB0. Finally it's working now. Next I'm going to try to decode Sony IR Remote (Sony Protocol).
 

I changed entire logic which will not read repeat pulse and will not get hang in while loop and along with EXT INT RB0. Finally it's working now. Next I'm going to try to decode Sony IR Remote (Sony Protocol).

post your code which is not hang in while loop.

- - - Updated - - -

I changed entire logic which will not read repeat pulse and will not get hang in while loop and along with EXT INT RB0. Finally it's working now. Next I'm going to try to decode Sony IR Remote (Sony Protocol).

post your code which is not hang in while loop.
 

Code:
static void interrupt
isr(void)
{
	RB2=0;	// LED blink for test
	if(INTF)	// wait for RB0 to go Low - EXT INT
	{
			// Read Start Pulse
			//	for(on=0;RB0==0 && on<=50000 ;on++)
			on=0;	while(RB0==0 && on<=2500)	on++;
			
			// Measure Start Pulse - if start pulse on time is ~9ms
			if(on>=2000 && on<=2200)
			{
				//RB2=0;
				
				temp=0;	while(RB0==1 && temp<=2500)	temp;
				// Measure Start Pulse - if start pulse off time is ~4.5ms
				if(temp>=1000 && temp<=1200)
				{
			
				// Read Address Pulse
				for(i=0;i<8;i++)
				{
					temp=0;	while(RB0==0 && temp<=2500)	temp;
					adrs[i]=0;	while(RB0==1 && adrs[i]<=2500)	adrs[i]++;
				}
				// Read Inverted Address Pulse
				for(i=0;i<8;i++)
				{
					temp=0;	while(RB0==0 && temp<=2500)	temp;
					adrs1[i]=0;	while(RB0==1 && adrs1[i]<=2500)	adrs1[i]++;
				}
				// Read Command Pulse
				for(i=0;i<8;i++)
				{
					temp=0;	while(RB0==0 && temp<=2500)	temp;
					dat[i]=0;	while(RB0==1 && dat[i]<=2500)	dat[i]++;
				}
				// Read Inverted Command Pulse
				for(i=0;i<8;i++)
				{
					temp=0;	while(RB0==0 && temp<=2500)	temp;
					dat1[i]=0;	while(RB0==1 && dat1[i]<=2500)	dat1[i]++;
				}

				// Convert Address Time to Binary
				lcd_command(0x01);
				for(i=0;i<8;i++)
				{
					adrs[i]=(adrs[i]>150)? 1 : 0;
					lcd_command(0x88-i-1);
					lcd_data(adrs[i]+0x30);
				}				
				
				// Convert Command Time to Binary
				for(i=0;i<8;i++)
				{
					dat[i]=(dat[i]>150)? 1 : 0;
					lcd_command(0xC8-i-1);
					lcd_data(dat[i]+0x30);
				}
				// Convert Inv Cmd Time to Binary
//				for(i=0;i<8;i++)
//				{				
//					dat1[i]=(dat1[i]>150)? 1 : 0;
//					lcd_command(0xC8-i-1);
//					lcd_data(dat1[i]+0x30);
//				}				

				// Binery to Decimal Convertionv - Address
				address=0;
				for(i=0;i<8;i++){
					if(adrs[i]==1){
						char power=1;
						for(char j=0; j<i; j++){
							power*=2;
						}
						address+=power;
					}
				}				
				// Binery to Decimal Convertion - Command
				cmd=0;
				for(i=0;i<8;i++){
					if(dat[i]==1){
						char power=1;
						for(char j=0; j<i; j++){
							power*=2;
						}
						cmd+=power;
					}
				}
//				cmd1=0;
//				for(i=0;i<8;i++){
//					if(dat1[i]==1){
//						char power=1;
//						for(char j=0; j<i; j++){
//							power*=2;
//						}
//						cmd1+=power;
//					}
//				}
				}

			// Display Decimal value on LCD
			lcd_command(0x8A);
			temp1=address;
			disp();
			lcd_command(0xCA);
			temp1=cmd;
			disp();
//			lcd_command(0xCA);
//			temp1=cmd1;
//			disp();	
			}	
	}	
		INTF=0;
		RB2=1;
}
 

Hey Jpsganesh,

I'm trying to decode Ir remote of NEC protocol. I have try with your interrupt but its not working. It will be a great pleasure if you can share the complete code.
I use PIC16f886 and HI-Tech C.

Thanks in advance
 

Sorry for the delayed response. Today only I got chance to check this forum. I'm at customer place now. By this month end I'll go back to my home and share u the code from my old backup. However my code hangs somewhere sometime after that I couldn't work on that. Meanwhile if u need any help let me know or u can share ur code so that I/someone can go through and debug it.
 

Sorry for the delayed response. Today only I got chance to check this forum. I'm at customer place now. By this month end I'll go back to my home and share u the code from my old backup. However my code hangs somewhere sometime after that I couldn't work on that. Meanwhile if u need any help let me know or u can share ur code so that I/someone can go through and debug it.

Hey Jpsganesh
Thanks for your reply. I couldn't work on it still not even a % so do help me with the code.
Hope you reply soon.

Thanks once again in advance
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top