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.

C codes for decoding RC5 signals using PIC microcontoller

Status
Not open for further replies.
rc5 code c program

vsmGuy said:
@CMOS : Wow ! It's so simple :)

@Picstudent : Have you come across RC5 code which exploits the manchester encoding of signal instead of times delays ?
Yes it is simple.
P.S. Yager's code uses state machine based manchester decoding.
 

rc5 ir code

I would argue that my code uses manchester decoding!
It uses the first 2 bits to calibrate the pulse timing and then uses that information to detect the hi-lo, lo-hi transitions. The data is decoded from the transitions and not the pulse lengths.

Added after 15 minutes:

To put the cat among the pigeons, no doubt, Yagers code works very well, but looking at the code, he is using pulse lengths for decoding and not the transitions.
 

rc5+ccs

What you think about this my simple code ?

unsigned int rc5_receive(void)
{
#define TIME_MAX (1728 / 2 + 100)
#define TIME_STEP (10)

int OffTime, OnTime, i;
unsigned int code;

if (!IR)
{
for (i = 0; i < TIME_MAX; i += TIME_STEP)
{
if (IR) break;

DelayUs(TIME_STEP);
}
if (i == TIME_MAX) return 0;

OffTime = i;

for (i = 0; i < TIME_MAX; i += TIME_STEP)
{
if (!IR) break;

DelayUs(TIME_STEP);
}
if (i == TIME_MAX) return 0;

OnTime = i;

DelayMs((OffTime + OnTime * 2 + OffTime / 2)/1000);

for (i = 0; i < 11; i++)
{
code = code << 1 + IR;

DelayMs((OffTime + OnTime)/1000);
}
return code;
}
return 0;
}
 

rc5 for pic

The code "works".

But correct code would decode the data from the transitions and not the pulse lengths.
 

ic to transmit rc5 coding

new version here, help me to get the data and addr

unsigned int rc5_receive(void)
{
#define TIME_MAX (1728 / 2 + 100)
#define TIME_STEP (10)

int OffTime, OnTime, i, j, k;
unsigned int code = 0;
unsigned char data, addr;

unsigned int bit_mask;

if (!IR)
{
//*********************************************************************
//* calclutale period lenght and duty cycle from the first transation
//*********************************************************************
for (i = 0; i < TIME_MAX; i += TIME_STEP)
{
if (IR) break;

DelayUs(TIME_STEP);
}
if (i == TIME_MAX) return 0;

OffTime = i;

for (i = 0; i < TIME_MAX; i += TIME_STEP)
{
if (!IR) break;

DelayUs(TIME_STEP);
}
if (i == TIME_MAX) return 0;

OnTime = i;

//********************************************
//* skip first 2 bit
//********************************************
j = (OffTime + OnTime * 2 + OffTime / 2);

for (k = 0; k < j; k += TIME_STEP)
DelayUs(TIME_STEP);


//********************************************
//* get address and data
//********************************************
for (i = 0; i < 12; i++)
{
if (i < 4)
addr = addr << 1 + IR;
else
data = data << 1 + IR;

j = (OffTime + OnTime);

for (k = 0; k < j; k += TIME_STEP)
DelayUs(TIME_STEP);
}


//*****************************************************
//* only to dump the data received with a single led
//*****************************************************
bit_mask = 1 << (8 - 1);

for (i = 0; i < 8; i++)
{
if ((data & bit_mask) == 0)
CSL = 0;
else
CSL = 1;

DelayMs(250);

data <<= 1;
}

return 1;
}
return 0;
}
Code:
 

+pic24 ir decoder code

int rc5_receive(unsigned int * RC5addr, unsigned int * RC5data)
{
#define TIME_MIN (200)
#define TIME_MAX (1728/2)
#define TIME_STEP (5)

int OffTime, OnTime, i, j, k;
unsigned int code = 0;
unsigned int gIRdata = 0, data = 0, addr = 0;

unsigned int bit_mask;

if (!IR)
{
for (i = 0; i < TIME_MAX && !IR; i += TIME_STEP)
{
DelayUs(TIME_STEP);
}
if (i > TIME_MAX) return -1;
if (i < TIME_MIN) return -1;

OffTime = i;

for (i = 0; i < TIME_MAX && IR; i += TIME_STEP)
{
DelayUs(TIME_STEP);
}
if (i > TIME_MAX) return -1;
if (i < TIME_MIN) return -1;

OnTime = i;


j = (OffTime + OnTime * 2 + OffTime / 2);

for (k = 0; k < j; k += TIME_STEP)
DelayUs(TIME_STEP);


//********************************************
//* get address and data
//********************************************
for (i = 0; i < 12; i++)
{
if (i > 5)
{
if (IR)
{
code <<= 1;
}
else
{
code <<= 1; code |= 1;
}
}

j = (OffTime + OnTime);

for (k = 0; k < j; k += TIME_STEP)
DelayUs(TIME_STEP);
}

data = code;

*RC5data = code;
*RC5addr = code;

sprintf(tmp, "Off %4d On %4d", OffTime, OnTime);
WriteLCD( 1, 1, tmp);

//*****************************************************
//* only to dump the data received with a single led
//*****************************************************
tmp[0] = '<';

bit_mask = 1 << (6 - 1);

for (i = 0; i < 6; i++)
{
if ((data & bit_mask) == 0)
tmp[i+1] = '0';
else
tmp[i+1] = '1';

data <<= 1;
}
tmp[i+1] = '>';
tmp[i+2] = '\0';

WriteLCD( 2, 2, tmp);

DelayMs(250);

return 0;
}
return -1;
}
 

sony sirc decoding

My firefly can do IR decoding. The nice thing is the 16F88 has a hardware USART and you can use a debugger with it and see your code running.
**broken link removed**
 
receive rc5 pic

Hello friends, for all a 2008 with much health, peace and harmony from Brazil. I work in the development of new products in a small business of toys here ... More expecificamente with circuit boards, but I think this topic (Remote Control) very good then come together posts with much enthusiasm. But what else I drew attention now, the figure is sent by (blueroomelectronics) ... I wonder if someone knows how to generate this image and or what software can give me this result. Thanks for attention and even more.
 

rc5 remote hi tech c

My friend, tell me one thing: You designed everything, piece by piece? If yes, it was great! However, it is very difficult?
I have used since 2003, the ECAD "Eagle" in my work and created some 3D images with good resolution will be to demonstrate how a possible PCBs.
Use the program POVRAY 3D ... And even with its deficiencies relating to the libraries, it is still very good.
I do not know the "Sketchup 3D." However, during the development of a new toy "Senninha GP," I heard the developers comment on this software. But as I said before, if there is no library of components is very difficult for me ...
Used much space in this topic and I appreciate your attention.
His work is excellent, congratulations.
 

decoder rc5 pic

Hello.

I need C program , to decode RC5 to run in Atmel 89C51 in C
It should be able to recognize system Address (TV,VCR)
upon valid address, receive IR stream.
Give output IRAddr IRData (Data and Address) after validating IR Stream.

Similar to one Posted by Metal(2004).

Code should be in C, I do not understand ASM,


Thanks
suds
 

rc5x decoder micro

hello,

I want to run btbass (One used by CMOS) code in 89C51 / 89C2051, what changes do I need to make ?

If some one has working c code for 89C51 or 89C2051 Please mail me..


Thanks
suds
 

rc5 infrared pic micro hi tech c

suds07 said:
hello,

I want to run btbass (One used by CMOS) code in 89C51 / 89C2051, what changes do I need to make ?

If some one has working c code for 89C51 or 89C2051 Please mail me..


Thanks
suds
Use BASCOM BASIC compiler for 8051. It comes with a RC5 library and works great.
 

simple rc5 decoder c sample source file

Hello

Has anyone ported this code to a PIC24F using C30?

I have tried to do this, but my knowledge of the PIC and CCS compilers isn't great, so it now compiles, but doesn't run correctly, so I am sure I am missing something fundamental!

Thanks

Richard
 

pic18 rc5 tutorial

Hi RichardH,
I have ported my code to the Pic24 but I use the MPLAB C30 compiler from Microchip. This is an excellent compiler for the pic 16 bit micros. It is a port of gcc which has been in continuous development for a number of years. Available as a free download from Microchip for the student version.

To those other guys who are using absolute times to decode, I think you will find that most ir handsets use cheap ceramic oscillators as a clock, and the pulse times can vary widely from the spec. You may get your program to decode your own handset, but try half a dozen handsets and see how your code performs.
Thats why RC5 transmits two ones at the start of the transmission. This is so you can calibrate the pulse time!

Here is my code, the system was using a 36.864Mips clock. I have left out the needed include files and the function that executes on a valid command. But the core code is there.

Code:
/*--------------------------------------------------------------------
 
  Filename    : rc_decoder.c 
  
----------------------------------------------------------------------

  CHANGE HISTORY

  Issue   Modifier  Date      Change Description
  1.0     RW        29/08/07  First Issue
    
--------------------------------------------------------------------*/

#include <your include file?>

/*--- Macros ---*/

#define RC_PIN PORTDbits.RD8

#define RC_ADDRESS      16U
#define RC_VOLUME_UP    16U
#define RC_VOLUME_DOWN  17U
#define RC_INPUT_UP     51U   
#define RC_INPUT_DOWN   52U      
#define RC_STATUS       53U   
#define RC_GAIN         54U   
#define RC_PHASE        55U   
#define RC_MUTE         13U   
#define RC_STANDBY      12U       

/*--- RC code structure ---*/

typedef struct
  {
  Bool toggle;
  uint8_t address;
  uint8_t command;
  }RC_CODE;

volatile RC_CODE RC_CODEbits;
volatile RC_EVENT RC_EVENTbits;

/*--- Local function prototype ---*/

static void init_timer_6(void);
static Bool rc_decoder(void);
static Bool wait_while_low(void);
static Bool wait_while_high(void);

/*--- initialise rc decoder interrupt ---*/

void init_rc_decoder(void)
  {
  IPC5bits.INT1IP = 2;      /* Low Priority */ 
  INTCON2bits.INT1EP = 1;   /* Negative edge interrupt */
  init_timer_6();
  RC_EVENTbits.event = False;
  IFS1bits.INT1IF = 0;
  IEC1bits.INT1IE = 1;
  TRISDbits.TRISD8 = 1;
  } 

/*--- Initialise Timer 6 (Used as RC timer) ---*/

static void init_timer_6(void)
  {
  T6CON = 0;  
  IPC11bits.T6IP = 1;    
  T6CONbits.TCKPS = 3;  /* Prescale 1:256 */ 
  PR6 = 720;            /* ~5mS Time out */      
  IFS2bits.T6IF = 0;
  IEC2bits.T6IE = 0;    /* Not using interrupt */
  T6CONbits.TON = 1;
  }

/*--- Rc interrupt ---*/

void __attribute__((__interrupt__, no_auto_psv)) _INT1Interrupt(void)
  {
  IEC1bits.INT1IE = 0; 
  
  if(rc_decoder()){
    execute_rc_event(); /* resolve RC event */
    }
    
  IFS1bits.INT1IF = 0;    
  IEC1bits.INT1IE = 1;
  }

/*--- RC decoder function ---*/

static Bool rc_decoder(void)
  {
  uint16_t bit_counter, bit_time, test_time, limit, rc_code;

  TMR6 = 0; 
  
  if(!wait_while_low()){
    return False;
    }

  if(!wait_while_high()){        
    return False;
    }

  bit_time = TMR6;                /* Calibrate bit time */
  TMR6 = 0; 
 
  test_time = (bit_time / 4) * 3; /* 3/4 bit time */
  limit = (bit_time / 4) * 5;     /* Out of limits */
  
  for(bit_counter = 0; bit_counter < 12; bit_counter++)
    {
    while(TMR6 < test_time){
      continue;
      }

    if(RC_PIN == 1)
      {
      if(!wait_while_high()){        
        return False;
        }

      bit_time = TMR6;
      TMR6 = 0;

      if(bit_time < limit){
        rc_code <<= 1;
        rc_code |= 1;
       }
      }
    else if(RC_PIN == 0)
      {
      if(!wait_while_low()){        
        return False;
        }

      bit_time = TMR6;
      TMR6 = 0;

      if(bit_time < limit){
        rc_code <<= 1;
        rc_code &= 0xfffe;
        }
      }
    }
  
  RC_CODEbits.address = (rc_code >> 6) & 0x001f;
  RC_CODEbits.command = rc_code & 0x003f;
  RC_CODEbits.toggle = (rc_code >> 11) & 0x0001; 

  return True;
  }

/*--- Wait while line is low ---*/

static Bool wait_while_low(void)
  {
  Bool result = True;

  IFS2bits.T6IF = 0;

  while(RC_PIN == 0){
    if(IFS2bits.T6IF == 1){  /* Timeout */
      result = False;
      break;
      }
    }
  return result;
  }

/*--- Wait while line is high ---*/

static Bool wait_while_high(void)
  {
  Bool result = True;

  IFS2bits.T6IF = 0;

  while(RC_PIN == 1){
    if(IFS2bits.T6IF == 1){  /* Timeout */
      result = False;
      break;
      }
    }
  return result;
  }

/*--- Execute rc event ---*/

void execute_rc_event(void)
  {
  //To Do

  }

/*--- End of File ---*/
 

infrared rc5 protocol delphi algorithm

Hi

Thats excellent - thanks!!

Only one question, I have an 8MHz xtal, how do I equate that to the 36.864Mips clock you mention......only I have never heard of a clock frequency being quoted in Mips

Thanks

Richard :)
 

rc6-6 mce mikrocontroller receiver protocol

Hi

Finally, just to be really dull, I dont have type defs for bool, uint8_t etc. am I missing a header file?

I know bool is part of C99, but I dont seem to have stdbool.h included with C30.

I presume uint8_t is an unsigned char?

thanks

Richard :D

Added after 3 hours 42 minutes:

Hi

So I have created type defs for the uint8_t, plus bool (although it does seem wasteful using a byte for 1 bit, but never mind), messed around with the timers (I only have 3 :cry:) and it works!

It works really well! with a Phillips original remote it is 100%, with a cheap remote it works, but I seem to get a double transmit, a spurious signal, then the correct one. Its not a problem as I can filter them out, but I presume this is the problem with cheap remotes.

One last thing, is there a standard for the type defs? or does everyone make up their own?

Thanks for all you help.

Richard
 

ir rc5 code 32-bit

The code I write has to be MISRA compliant. The types used are those recommended by MISRA. This is the include file we use.
It may seem wastful to use a byte for a boolean, (the standard is actually an int), but it helps to write clear code. Most of them are local variables, so the memory is reclaimed.
Also, plenty of memory available in the 16-bit micros.

Code:
/*--------------------------------------------------------------------
  File Name     : PosixTypes.h 
  Description   : ISO (Posix) typedef file for pic
                : Misra Rule 6.3 (advisory)                      

  Revision      : 1.0 
  Date          : 21/08/05 
  
----------------------------------------------------------------------*/  

#ifndef TYPES_H
#define TYPES_H
            
/*--- Standard type definitions. ---*/

/* Plain char, only to be used for the storage and use of character values. Misra Rule 6.1 (Required) */

typedef unsigned char   uint8_t;    /* unsigned 8 bit type definition */
typedef signed char     int8_t;     /* signed 8 bit type definition */
typedef unsigned int    uint16_t;   /* unsigned 16 bit type definition */
typedef signed int      int16_t;    /* signed 16 bit type definition */
typedef unsigned long   uint32_t;   /* unsigned 32 bit type definition */
typedef signed long     int32_t;    /* signed 32 bit type definition */
typedef unsigned char   Bool;       /* Bool type definition */

/*--- Standard constant definition. ---*/

#define False ((Bool)0x00U)
#define True  ((Bool)0x01U)

/*--- End of file. ---*/

#endif
 

picsc rc5.h

Hi

That all makes sense and I agree with your comment about making the code more readable.

I come from an 8051 background with bit data areas, so you get used to having this available - its a bit of a learning curve swapping over to the PIC, altho the 24 series do seem prett powerful, plus they are cheap.

The IR routine is rock solid BTW, had it running most of the day on several remotes with no problems - really nice bit of code.

Thanks for your help.

Richard
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top