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.
microchip rc5

No problem, glad to be of help.

Try out my free RTOS for 16-bit pics posted on eda board here:
 
Re: PIC RC5 Code

Hi,

I am trying to port the code for C18 compiler but am not able to.

This is the code i have converted but its not working for RC5. Can someone please help me.

Code:
#include <p18cxxx.h>
#include <delays.h>

#pragma config WDT = OFF, LVP = OFF, OSC = XT, DEBUG = OFF

#define IR_pin PORTBbits.RB0
#define TIME_MIN  (5)
#define TIME_MAX  (11)
#define TIME_STEP (2)
#define LED0 PORTCbits.RC0
#define LED1 PORTCbits.RC1
#define LED2 PORTCbits.RC2
#define LED3 PORTCbits.RC3
#define LED4 PORTCbits.RC4

int RC5_receive(unsigned int *, unsigned int *);
void Delay100Us(unsigned char);
void applyIR(void);

void Delay100Us(unsigned char time)
{
	char x;
	for(x=0;x<time;x++)
		Delay10TCYx(9);
}

unsigned int IR_addr, IR_data = 0;

void applyIR(void)
{
	switch(IR_data)
	{
		case 0: LED0 ^= 1;break;
		case 1: LED1 ^= 1;break;
		case 2: LED2 ^= 1;break;
		case 3: LED3 ^= 1;break;		
		case 4: LED4 ^= 1;break;
	}
}	

void main(void)
{
	ADCON1 = 0x0F;
	TRISB = 0x01;
	TRISA = 0x00;
	PORTB = 0x00;
	TRISC = TRISD = TRISE = 0x00;
	PORTA = PORTC = PORTD = PORTE = 0x00;
	PORTC = 0x55;
	while(1)
	{
		RC5_receive(&IR_addr, &IR_data);
		applyIR();
	}
}

int RC5_receive(unsigned int * RC5addr, unsigned int * RC5data) 
{
    int           OffTime, OnTime, DevTime, DiTime, i, j, k;
    unsigned int  data = 0, addr = 0;
    unsigned int  bit_mask;

    if(!IR_pin)
    {
		for(OffTime = 0; !IR_pin && OffTime < TIME_MAX; OffTime += TIME_STEP){Delay100Us(TIME_STEP);}
		if (OffTime > TIME_MAX) return -1;
		if (OffTime < TIME_MIN) return -1;

		for(OnTime = 0; IR_pin && OnTime < TIME_MAX; OnTime += TIME_STEP){Delay100Us(TIME_STEP);}
		if (OnTime > TIME_MAX) return -1;
		if (OnTime < TIME_MIN) return -1;


		//* skip token
        DevTime = (2 * OffTime + OnTime + OffTime / 2);

        for (k = 0; k < DevTime; k += TIME_STEP){Delay100Us(TIME_STEP);}
	
		//* get address and data
		DiTime  = (OffTime + OnTime);
	
		for (i = 0; i < 5; i++)
		{
		    if(IR_pin) {addr <<= 1;} else{addr <<= 1; addr |= 1;}
		    for (k = 0; k < DiTime; k += TIME_STEP){Delay100Us(TIME_STEP);}
		}
		for (i = 0; i < 6; i++)
		{
		    if(IR_pin){data <<= 1;}else{data <<= 1; data |= 1;}
		    for (k = 0; k < DiTime; k += TIME_STEP){Delay100Us(TIME_STEP);}
		}
	
		*RC5data = data;
		*RC5addr = addr;
		return 0;
    }
    return -1;
}
 

Re: PIC RC5 Code

@Yager
HI
I want to ask a simple question that will your code work for every remote or not.
I am making this project and after going through the replies i am going to test your code.
But i have some confusion. I am making a project that take data from the remote and display it on the LCD.
Displaying on the LCD is other issue but is it work for every remote in the market or the specific remote.
My remote uses RC5 protocol.

Thanks

Added after 32 minutes:

I am using 18F452 and the max232 is attached to the 4 and 5 pin of 18F and IR is connected at the 13 pin. What changes that i have to make in your project to run it on my PIC board.

Thanks I will wait for your replay.
 

Re: +pic24 ir decoder code

hi mate can i use this code on a 16f690 pic
 

Re: rc5 pic example

Good to hear the code works ok for you.
As for the noise, first check that there isnt something else transmitting. I once had a problem and it turned out that my laptop was intermitantly sending out ir signals.
also, the IS1U60 has quite a good optical filter that blocks out non ir sources.
I will try to optimise the code so that when it is calibrating the pulse length, it checks that it is close to 1.8mS long and rejects it if it isnt.
Also, after using the results, set rc5valid to false.

To get better results, a resonator or xtal is better than a rc oscillator for clock source, but with a 12F629 I dont suppose you have that choice!

hi @btpass
i am trying to use your rc5 code on pic16f690 but keep getting errors please can u help me see where i am going wrong in the code i am using high C compiler. thanks.


header /////////////**********
/*--- rc5decode.h ---*/

#ifndef RC5DECODE
#define RC5DECODE

/*--- Function prototype ---*/

unsigned char rc5Decode(void);

/*---- globals ---*/

extern unsigned char command; /* rc5 command code */
extern unsigned char address; /* rc5 system address */
extern unsigned char rc5valid; /* valid rc5 data flag */

#endif

/*--- Macros ---*/

#define IR_IN _PORTA,2 /* Infra Red input pin */
#define TMR _TMR0 /* Pulse timer */

/*--- rc5 infra red codes ---*/

#define SYSTEM_ADD 0x10 /* System address */

#define RC5_VOL_UP 0x10 /* VOL+ */
#define RC5_VOL_DOWN 0x11 /* VOL- */
#define RC5_LINEAR_FUNCTION_UP 0x4D /* LINEAR FUNCTION + */
#define RC5_LINEAR_FUNCTION_DWN 0x02 /* LINEAR FUNCION - */
#define RC5_NEMERIC_KEY_0 0x00 /* CNUMERIC KEY 0 */
#define RC5_NUMERIC_KEY_1 0x01 /* NUMERIC KEY 1 */
#define RC5_NUMERIC_KEY_2 0x02 /* AUX1 */
#define RC5_STANDBY 0x09 /* STANDBY */
#define RC5_MUTE 0x0D /* MUTE */


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



////////////c code**********


#include <htc.h>
#include <pic.h>
#include "RC_5header.h"
#define _XTAL_FREQ 4000000
#define _PWRTE_ON EQU H'3FEF' ; PWRT enabled
#define _MCLRE_ON EQU H'3FFF' ; MCLR pin function is MCLR
#define _WDT_ON EQU H'3FFF' ; WDT enabled
#define _CP_ON EQU H'3FBF' ; Program memory code protection is enable


__CONFIG( _CP_ON &_PWRTE_ON &_WDT_ON &_MCLRE_ON );
/*--- globals ---*/

unsigned char command;
unsigned char address;
unsigned char temp;
unsigned char timer;
unsigned char rc5valid;

void select_operation(void);

//*interrupt function ta call functionality when the remote input is detected*//
void interrupt isr(void);

/*--- rc5 decode function ---*/

unsigned char rc5Decode(void)
{
#asm

;------ calibrate timing

bcf 3,5 ;select bank 0
clrf TMR ;start timer
call Wlow ;get the pulse length
call Whigh

btfsc TMR,7 ;test for timer overflow
goto codeError ;bail out

movf TMR,w ;save pulse length
clrf TMR ;start timer

movwf _timer ;take the pulse length,
movwf _temp ;save it
bcf 3,0 ;clear carry
rrf _temp,f ;divide by 2
bcf 3,0 ;clear carry
rrf _temp,f ;divide by 4
movf _temp,w ;and subtract to get
subwf _timer,f ;3/4 pulse length

movlw 0x0c
movwf _temp ;init bit counter

;------ wait for start of data

nextBit movf _timer,w ;wait 3/4 pulse length
subwf TMR,w
btfss 3,2 ;take a look
goto nextBit

;------ start of data stream

btfss IR_IN ;if its high
goto waitlow ;gonna be an 0

;------ wait for high 1

call Whigh ;if its low
bsf 3,0 ;gonna be a 1
goto clock

;------ wait for low 0

waitlow call Wlow
bcf 3,0 ;gonna be an 0

;------ clock data

clock clrf TMR ;restart timer
rlf _command,f ;save the bit
rlf _address,f
decfsz _temp,f ;done all bits?
goto nextBit

;------ get system address, toggle bit and command code

movf _command,w ;copy low byte
movwf _temp ;into temp
rlf _temp,f ;need to shift 2 bits
rlf _address,f ;into address
rlf _temp,f
rlf _address,f ;system address is 5 bits

movlw 0x3f ;mask system address + toggle bit
andwf _address,f

movlw 0x3f ;mask command code
andwf _command,f ;command code is 6 bits
goto rc5ok ;done ok

;------ wait while low

Wlow btfsc TMR,7 ;test for timer overflow
return ;bail out
btfss IR_IN
goto Wlow
return

;------ wait while high

Whigh btfsc TMR,7 ;test for timer overflow
return ;bail out
btfsc IR_IN
goto Whigh
return

rc5ok movlw 0x01
movwf _rc5valid
goto rc5end
codeError clrf _rc5valid
rc5end nop

#endasm

return rc5valid;
}

void interrupt isr(void)
{

if(rc5Decode())
{
switch(PORTB)
{
case 'RC5_NUMERIC_KEY_0':
PORTC = 0x03;
break;
case 'RC5_NUMERIC_KEY_1':
PORTC = 0x0C;
break;
default :
PORTC = 0x0F;
}
}
INTF = 0;
}

void select_operation(void)
{
PORTC = 0x0F;
}


void main()
{
PORTA = 0xFF;
TRISA = 0;

PORTB = 0xFF;
TRISB = 0;

PORTC = 0x00;
TRISC = 0;

GIE = 1;
INTE = 1;

while(1);


}


thanks in advance
 

Re: PIC RC5 Code

Nice RTOS btbass.

Any recommendations as to reference material, books, literature, etc, that aided in coding it?
 

Re: PIC RC5 Code

Try this for your rc5 decoder.
 

Attachments

  • Rc5_Decoder.zip
    6.3 KB · Views: 121

Re: PIC RC5 Code

Hi bigdogguru,
The RTOS was inspired by an old book I have called 'Born to Code in C' by Herbert Schildt which describes a multitasking system for PC's in DOS.
I used his code on several projects and it worked very well.

The book I used to write the program was 'dsPIC30F Programmers Reference Manual' which is a Microchip publication I have in hardcopy. I don't think they do it any more, as now you can download it as a pdf.

The assembly language for the Pic 16-bit family is really powerful.
In my opinion it is the cleanest most logical assembly language Ive used.

I have posted a light version on eda board here
https://www.edaboard.com/threads/203855/
 
Last edited:

Re: rc5 code yager

Hi btbass,
I tried your code with 12F629, and it is working like charm.

My conenctions are like this
GPIO2 = IR Receiver
GPIO1 = RX Pin (MAX232)
GPIO0 = TX Pin (MAX232)

Thanks a lot buddy!! :D

Here is the full code.
Code:
//Main.c
/*------ RC5 decoder program Version 1.0 (by btbass) 'bob the bass' 4MHz clock

;------ RC5 code is 14 bits each of 1.8mS duration with carrier frequency of 36KHz.
;------ A '0' is a mid pulse transition from high to low.
;------ A '1' is a mid pulse transition from low to high.
;------ The first 2 bits are always 1, for timing calibration.
;------ The next bit is the toggle bit, indicating a new keypress.
;------ Then 5 bits of address and 6 bits of command code.
;------ The IR receiver inverts the data stream. (check, but most do!)
;------ This program uses the first 2 bits to calibrate the timing of one pulse length.
;------ It then waits 3/4 pulse length and looks at the input.
;------ If its high, it waits for a low '0'.
;------ If it's low, it waits for a high '1', then resets the timer on the transition.
;------ It returns 0x01 if the code is ok and 0x00 if an error.
;------ The rc5 system address is returned in address, the command in command.
;------ The toggle bit is bit 5 of the address byte.
;------ Using a 4 Meg xtal with timer divided by 128. */

#include <pic.h>
#include <stdio.h>
#include "rc5decode.h"

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS);

/*--- globals ---*/
unsigned char command;
unsigned char address;
unsigned char temp;
unsigned char timer;
unsigned char rc5valid;

#define	PORTBIT(adr, bit)	((unsigned)(&adr)*8+(bit))
static bit	IR_PIN @	PORTBIT(GPIO, 2);

/*--- rc5 decode function ---*/
//static void interrupt 
unsigned char rc5decode(void)
{
  #asm
                                             
;------ calibrate timing

          bcf     3,5         ;select bank 0
          clrf    TMR         ;start timer     
          call    Wlow        ;get the pulse length                           
          call    Whigh

          btfsc   TMR,7       ;test for timer overflow
          goto    codeError   ;bail out

          movf    TMR,w       ;save pulse length
          clrf    TMR         ;start timer                     

          movwf   _timer      ;take the pulse length,
          movwf   _temp       ;save it
          bcf     3,0         ;clear carry
          rrf     _temp,f     ;divide by 2
          bcf     3,0         ;clear carry
          rrf     _temp,f     ;divide by 4
          movf    _temp,w     ;and subtract to get
          subwf   _timer,f    ;3/4 pulse length

          movlw   0x0c
          movwf   _temp       ;init bit counter
                     
;------ wait for start of data

nextBit   movf    _timer,w    ;wait 3/4 pulse length
          subwf   TMR,w
          btfss   3,2         ;take a look
          goto    nextBit
                                                                                                                           
;------ start of data stream

          btfss   IR_IN       ;if its high
          goto    waitlow     ;gonna be an 0
                       
;------ wait for high 1

          call    Whigh       ;if its low
          bsf     3,0         ;gonna be a 1
          goto    clock       
           
;------ wait for low 0

waitlow   call    Wlow       
          bcf     3,0         ;gonna be an 0
           
;------ clock data

clock     clrf    TMR         ;restart timer
          rlf     _command,f  ;save the bit
          rlf     _address,f
          decfsz  _temp,f     ;done all bits?
          goto    nextBit                 
                           
;------ get system address, toggle bit and command code

          movf    _command,w  ;copy low byte
          movwf   _temp       ;into temp
          rlf     _temp,f     ;need to shift 2 bits
          rlf     _address,f  ;into address
          rlf     _temp,f
          rlf     _address,f  ;system address is 5 bits

          movlw   0x3f        ;mask system address + toggle bit
          andwf   _address,f
           
          movlw   0x3f        ;mask command code
          andwf   _command,f  ;command code is 6 bits         
          goto    rc5ok       ;done ok                       
           
;------ wait while low

Wlow      btfsc   TMR,7       ;test for timer overflow
          return              ;bail out
          btfss   IR_IN
          goto    Wlow
          return 
           
;------ wait while high

Whigh     btfsc   TMR,7       ;test for timer overflow
          return              ;bail out
          btfsc   IR_IN
          goto    Whigh
          return   

rc5ok     movlw   0x01
          movwf   _rc5valid
          goto    rc5end
codeError clrf    _rc5valid
rc5end    nop       

  #endasm
	return rc5valid;
}

static void interrupt
isr(void)
{
	if(rc5decode())
	{
		address &= 0x1F;
		if(address == REMOTE_ADDRESS)
			printf("%d\r\n",command);
			//printf("Address:%d\r\nCommand:%d\r\n\n",address,command);
	}
	INTF = 0;
}

void main(void)
{
    OSCCAL = _READ_OSCCAL_DATA(); 		// restore oscillator calibration

	CMCON = 0x07;	// turn off comparator
	TRISIO = 0x3E;
	OPTION = 0x06;
	
	INTE = 1;		// enable the external interrupt
	GIE = 1;		// Global interrupt enable

	while(1);
}

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

Code:
//Serial.c
/*
 *	Serial port driver (uses bit-banging)
 *	for 16Cxx series parts.
 *
 * 	IMPORTANT: Compile this file with FULL optimization
 *
 *	Copyright (C)1996 HI-TECH Software.
 *	Freely distributable.
 */
#include	<pic.h>
/*
 *	Tunable parameters
 */

/*	Transmit and Receive port bits */
#define SERIAL_PORT	GPIO
#define SERIAL_TRIS	TRISIO
#define	TX_PIN		0
#define RX_PIN		1

/*	Xtal frequency */
#define	XTAL	4000000

/*	Baud rate	*/
#define	BRATE	9600

/*	Don't change anything else */
#define SCALER		10000000
#define ITIME		4*SCALER/XTAL	/* Instruction cycle time */
#if BRATE > 1200
 #define	DLY		3		/* cycles per null loop */
 #define	TX_OHEAD 13		/* overhead cycles per loop */
#else
 #define	DLY		9		/* cycles per null loop */
 #define TX_OHEAD  14
#endif
#define	RX_OHEAD	12		/* receiver overhead per loop */

#define	DELAY(ohead)	(((SCALER/BRATE)-(ohead*ITIME))/(DLY*ITIME))

static bit	TxData @ (unsigned)&SERIAL_PORT*8+TX_PIN;	/* Map TxData to pin */
static bit	RxData @ (unsigned)&SERIAL_PORT*8+RX_PIN;	/* Map RxData to pin */
#define	INIT_PORT	SERIAL_TRIS |= 1<<RX_PIN				/* set up I/O direction */

void
putch(char c)
{
	unsigned char	bitno;
#if BRATE > 1200
	unsigned char	dly;
#else
	unsigned int	dly;
#endif

	INIT_PORT;
	TxData = 0;			/* start bit */
	bitno = 12;
	do {
		dly = DELAY(TX_OHEAD);	/* wait one bit time */
		do
			/* waiting in delay loop */ ;
		while(--dly);
		if(c & 1)
			TxData = 1;
		if(!(c & 1))
			TxData = 0;
		c = (c >> 1) | 0x80;
	} while(--bitno);
NOP();
}

char
getch(void)
{
	unsigned char	c, bitno;
#if BRATE > 1200
	unsigned char	dly;
#else
	unsigned int	dly;
#endif

	for(;;) {
		while(RxData)
			continue;	/* wait for start bit */
		dly = DELAY(3)/2;
		do
			/* waiting in delay loop */ ;
		while(--dly);
		if(RxData)
			continue;	/* twas just noise */
		bitno = 8;
		c = 0;
		do {
			dly = DELAY(RX_OHEAD);
			do
			/* waiting in delay loop */ ;
			while(--dly);
			c = (c >> 1) | (RxData << 7);
		} while(--bitno);
		return c;
	}
}

char
getche(void)
{
	char c;

	putch(c = getch());
	return c;
}

Code:
/*--- rc5decode.h ---*/

#ifndef RC5DECODE
#define RC5DECODE

/*--- Function prototype ---*/

unsigned char rc5Decode(void);

/*---- globals ---*/

extern unsigned char command;   /* rc5 command code */
extern unsigned char address;   /* rc5 system address */
extern unsigned char rc5valid;  /* valid rc5 data flag */

#endif

/*--- Macros ---*/
#define REMOTE_ADDRESS	19
#define IR_IN _GPIO,2  /* Infra Red input pin */
#define TMR   _TMR0     /* Pulse timer */

/*--- rc5 infra red codes ---*/

#define SYSTEM_ADD    0x10    /* System address */

#define RC5_VOL_UP    0x10    /* VOL+ */
#define RC5_VOL_DOWN  0x11    /* VOL- */
#define RC5_PHONO     0x01    /* PHONO */
#define RC5_TUNER     0x02    /* TUNER */
#define RC5_CD        0x03    /* CD */
#define RC5_AV        0x04    /* AV */
#define RC5_AUX1      0x08    /* AUX1 */
#define RC5_AUX2      0x09    /* AUX2 */
#define RC5_MUTE      0x0D    /* MUTE */

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


hi @CMOS i am trying to use the same code on pic16f690 but i keep coming up with errors can u help me look at my code to see where the errors lie thanks ;


#include <htc.h>
#include <pic.h>
#include "RC_5header.h"
#define _XTAL_FREQ 4000000
#define _PWRTE_ON EQU H'3FEF' ; PWRT enabled
#define _MCLRE_ON EQU H'3FFF' ; MCLR pin function is MCLR
#define _WDT_ON EQU H'3FFF' ; WDT enabled
#define _CP_ON EQU H'3FBF' ; Program memory code protection is enable


//CONFIG'()';// _CP_ON);// &_PWRTE_ON &_WDT_ON &_MCLRE_ON );
/*--- globals ---*/

unsigned char command;
unsigned char address;
unsigned char temp;
unsigned char timer;
unsigned char rc5valid;

void select_operation(void);

//*interrupt function ta call functionality when the remote input is detected*//
void interrupt isr(void);

/*--- rc5 decode function ---*/

unsigned char rc5Decode(void)
{
#asm

;------ calibrate timing

bcf 3,5 ;select bank 0
clrf TMR ;start timer
call Wlow ;get the pulse length
call Whigh

btfsc TMR,7 ;test for timer overflow
goto codeError ;bail out

movf TMR,w ;save pulse length
clrf TMR ;start timer

movwf _timer ;take the pulse length,
movwf _temp ;save it
bcf 3,0 ;clear carry
rrf _temp,f ;divide by 2
bcf 3,0 ;clear carry
rrf _temp,f ;divide by 4
movf _temp,w ;and subtract to get
subwf _timer,f ;3/4 pulse length

movlw 0x0c
movwf _temp ;init bit counter

;------ wait for start of data

nextBit movf _timer,w ;wait 3/4 pulse length
subwf TMR,w
btfss 3,2 ;take a look
goto nextBit

;------ start of data stream

btfss IR_IN ;if its high
goto waitlow ;gonna be an 0

;------ wait for high 1

call Whigh ;if its low
bsf 3,0 ;gonna be a 1
goto clock

;------ wait for low 0

waitlow call Wlow
bcf 3,0 ;gonna be an 0

;------ clock data

clock clrf TMR ;restart timer
rlf _command,f ;save the bit
rlf _address,f
decfsz _temp,f ;done all bits?
goto nextBit

;------ get system address, toggle bit and command code

movf _command,w ;copy low byte
movwf _temp ;into temp
rlf _temp,f ;need to shift 2 bits
rlf _address,f ;into address
rlf _temp,f
rlf _address,f ;system address is 5 bits

movlw 0x3f ;mask system address + toggle bit
andwf _address,f

movlw 0x3f ;mask command code
andwf _command,f ;command code is 6 bits
goto rc5ok ;done ok

;------ wait while low

Wlow btfsc TMR,7 ;test for timer overflow
return ;bail out
btfss IR_IN
goto Wlow
return

;------ wait while high

Whigh btfsc TMR,7 ;test for timer overflow
return ;bail out
btfsc IR_IN
goto Whigh
return

rc5ok movlw 0x01
movwf _rc5valid
goto rc5end
codeError clrf _rc5valid
rc5end nop

#endasm

return rc5valid;
}

void interrupt isr(void)
{

if(rc5Decode())
{
PORTC = 0x0F;
}

INTF = 0;
}

void select_operation(void)
{
PORTC = 0x0F;
}


void main()
{
PORTA = 0xFF;
TRISA = 0;

PORTB = 0xFF;
TRISB = 0;

PORTC = 0x00;
TRISC = 0;

GIE = 1;
INTE = 1;
INTEDG = 0;

while(1);


}

---------- Post added at 06:18 ---------- Previous post was at 04:59 ----------

thanks @btpass for the code Built it successful but still not getting response from led's when pressing button on remote , i am using a vishay tsop1236 infra red receiver , tried the code with inverted and direct input to the RA2/INT pi but still no result , using RC5-R remote control. after i build the project ((NULL)) was put into all the assciated files in the files window.. any advice please thanks
 

Re: rc5 code yager

testing the code to illuminate led's at the C port when there's a valid transmission and still not getting any indicative output
 

Re: PIC RC5 Code

You are setting all your ports to outputs?
Also check the ANSEL register is clear

Code:
void main()
  {
  ANSEL = 0;            /* Configure pins as digital I/O */

  PORTA = 0xFF;
  TRISA = 0;		/* All outputs ??? */

  PORTB = 0xFF;
  TRISB = 0;

  PORTC = 0x00;
  TRISC = 0;

  GIE = 1;
  INTE = 1;
  INTEDG = 0;

  while(1); 
 }
 

Re: PIC RC5 Code

ok thanks alot btpass, but now i am gettin errors for the __CONFIG line saying unidentified symbol "MCLREN", "WDTEN", "PWRTEN" , "CP", "XT"
 

Re: PIC RC5 Code

Code:
  __CONFIG(XT & CP & PWRTEN & WDTEN & MCLREN);

This config line compiles ok for me.
The config line should be the first line in the code after the include files.
The symbols are defined in the 'pic16f685.h' file which is conditionally called from the 'pic.h' file.
You can look in the file and see the definitions at the end of the file.

You only need to include the <htc.h> file as that calls the <pic.h> file.
 

Re: PIC RC5 Code

__CONFIG( CP_ON & PWRTE_ON & MCLRE_ON); used this and the code compiles ok ,
the intended function for the isr i wrote is for led's in the c port to come on for a valid transmission but i still am not seeing the led's come on. is this a wrong piece of code or is the rc5 not working

void interrupt isr(void)
{
unsigned char PORTC;

if(rc5Decode())
{
switch(command)
{
case RC5_NEMERIC_KEY_0:
PORTC == 0x03;
break;

case RC5_NUMERIC_KEY_1:
PORTC == 0x0C;
break;

default :
PORTC = 0x0F;
break;
}
}
INTF = 0;
}

---------- Post added at 13:50 ---------- Previous post was at 13:50 ----------

i'm using pic16f690
 

Re: PIC RC5 Code

Make sure you have disabled the watchdog timer or periodically reset it.

Code:
void interrupt isr(void)
  {
  if(rc5Decode())
    {
    switch(command)
      {
      case RC5_NEMERIC_KEY_0:
        PORTC = 0x03;
        break;

      case RC5_NUMERIC_KEY_1:
        PORTC = 0x0C;
        break;

      default :
        PORTC = 0x0F;
        break;
      }
    }

  INTF = 0;
  }


---------- Post added at 14:28 ---------- Previous post was at 14:00 ----------

If you are using more than one interrupt, you need to check the interrupt source.
Code:
void interrupt isr(void)
  {
  if(INTF)
    {
    if(rc5Decode())
      {
      switch(command)
        {
        case RC5_NEMERIC_KEY_0:
          PORTC = 0x03;
          break;

        case RC5_NUMERIC_KEY_1:
          PORTC = 0x0C;
          break;

        default :
          PORTC = 0x0F;
          break;
        }
      }

    INTF = 0;
    }
  }
 

Re: PIC RC5 Code

thanks alot btpass really appreciate your time ... but i want to ask will this code also respond to input from a universal remote control?? or does it specifically have to be rc5 remote thanks
 

Re: PIC RC5 Code

So hopefully it is now working?

The code is only good for RC5 protocol. It has to be RC5.
 

Re: PIC RC5 Code

thanks mate
 

Hi,
I have written an interrupt driven RC5 decoder for CCS C compiler.
You can get it here:
**broken link removed**

Regards!
 
  • Like
Reactions: adidav

    adidav

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top