RC5 lib

58 views
Skip to first unread message

hans

unread,
Jun 15, 2021, 4:49:23 AM6/15/21
to jallib
Is there beside the SIRC lib also one for sending/receiving RC5 ?

Rob CJ

unread,
Jun 15, 2021, 12:31:02 PM6/15/21
to jal...@googlegroups.com
Hi Hans,

Some years ago (in 2014 to be exact) I wrote a decoder routine that is capable of decoding RC5 and RC6 messages. It works on an interrupt basis. I wrote two variants, one using Timer 0 and one using Timer 1. I attached the sources files in the attached zip file.

I could make a JAL library out of it - since these source files are not yet Jallib compilant - and make it part of Jallib. I could then incorporate the timer part in the decoder part so that you only have one library to include. 

Currently I am enjoying my vacation so I am not able to test them but I think they work. The main program uses a USART to write the received RC5 or RC6 message. The UART part is also included in the zip file.  

I could make an RC5 and RC6 encoder program since I have done that in the past because I have worked at Philips many years ago and was one of the contributors of the Philips RC6 standard 🙂. As you may know, for the encoder you need a 36 kHz modulated signal to drive the Infra Red LED so you need a PWM signal for that. 

Kind regards,

Rob






Van: jal...@googlegroups.com <jal...@googlegroups.com> namens hans <hansvanve...@gmail.com>
Verzonden: dinsdag 15 juni 2021 10:49
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] RC5 lib
 
Is there beside the SIRC lib also one for sending/receiving RC5 ?

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/0e2b7ff9-dfde-4d3b-8db2-72e3c50ee21fn%40googlegroups.com.
IR_RC5_RC6_Decoder.zip

hans

unread,
Jun 15, 2021, 3:54:26 PM6/15/21
to jallib

Hi Rob,

Thanks for responding, even though you're on vacation. First some more information. I have a device that I normally operate with push buttons, but that can also work with RC5 if i connect  a Tsop1836 on it, for example. I also have the codes used for address and commands. So I want to use a Pic as a transmitter.

Actually I don't need the whole IR part  because I can also connect an output of the PIC directly to the RC5 input of the device.. I have already found the information about what the pulse train should look like.

At least it keeps the gray matter flexible.

Greetings and have a nice holiday

Hans

Op dinsdag 15 juni 2021 om 18:31:02 UTC+2 schreef rob...@hotmail.com:

Rob CJ

unread,
Jun 16, 2021, 2:04:59 AM6/16/21
to jal...@googlegroups.com
Hi Hans,

I understand what you are doing so you do not need the 36 kHz carrier. That makes it even simpler. In that case you only need a timer to generate the RC5 bi-phase signal. Will you be able to do that or do you need some help with that?

Met vriendelijke groet,
Rob Jansen

From: jal...@googlegroups.com <jal...@googlegroups.com> on behalf of hans <hansvanve...@gmail.com>
Sent: Tuesday, June 15, 2021 9:54:26 PM
To: jallib <jal...@googlegroups.com>
Subject: Re: [jallib] RC5 lib
 

hans

unread,
Jun 16, 2021, 2:39:19 PM6/16/21
to jallib

Hi Rob,

I've tried a few things but it's not as easy as I thought. Simply removing the IR receiver and replacing it with an optocoupler will not work. There's something behind it with no license plates. So I put the case back together and checked with a standard remote. He's working again. End of story : I do need a lib for the normal IR operation. If it can send and receive. I hope you have the time for it.

Here is what i have done.

 I have a very old RC5 reader and on that one the data reeceived is correct, adres and commands. But not on the one i like to use. (as i said above)

-- Title: RC5 test

--

 

-- ------------------------------------------------------

--

--

include 16f877a                     -- target PICmicro

--

 

pragma target clock 20_000_000      -- oscillator frequency

--

pragma target OSC      HS                        -- crystal or resonator

pragma target WDT      DISABLED                  -- watchdog

pragma target DEBUG    DISABLED                  -- no debugging

pragma target BROWNOUT DISABLED                  -- no brownout reset

pragma target LVP      DISABLED---ENABLED                   -- low voltage programming

--

 

enable_digital_io()                 -- make all pins digital I/O

 

-- library with delay procedures

include delay

 

alias RC5    is pin_D2

pin_D2_direction  = output

RC5 = low

 

 

include delay                         -- fetch delay library

--

 procedure HOOG is

 RC5 = low

 _usec_delay(889)

 RC5 = high

  _usec_delay(889)

  end procedure

 

  procedure LAAG is

 RC5 = high

 _usec_delay(889)

 RC5 = low

  _usec_delay(889)

  end procedure

 

  procedure BASIS is

  hoog

  hoog

  laag

  laag

  laag

  hoog

  laag

  hoog

  end procedure

 

  procedure   START_PAUZE is

  for 10 loop

  basis

  hoog

  hoog

  laag

  hoog

  laag

  hoog

  delay_1mS(114)

  end loop

  end procedure

 

  procedure STOP is

  for 10 loop

  basis

  hoog

  hoog

  laag

  hoog

  hoog

  laag

  delay_1mS(114)

  end loop

  end procedure

 

  procedure VOLGENDE is

  for 10 loop

  basis

  hoog

  laag

  laag

  laag

  laag

  laag

  delay_1mS(114)

  end loop

  end procedure

 

 

   delay_1S(5)

   forever loop

 

   start_pauze

   delay_1S(2)

   start_pauze

   delay_1S(2)

   start_pauze

   delay_1S(2)

   stop

   delay_1S(2)

   volgende

   delay_1S(2)

   start_pauze

   delay_1S(2)

   stop

   delay_1S(5)

  

   end loop

  

 

 

 

Thanks again.

regards

Hans


Op woensdag 16 juni 2021 om 08:04:59 UTC+2 schreef rob...@hotmail.com:

Rob CJ

unread,
Jun 17, 2021, 1:47:23 PM6/17/21
to jal...@googlegroups.com
Hi Hans, 

I had a look at your program. The procedure called 'Basis' raises some questions.

It starts with two start bits (both 'hoog') but the third bit is a toggle bit. If you press a key on the remote control and you keep it pressed. The same command is repeated with the same toggle bit. The receiver then knows that it is still the same command. As soon as you release a key and press it again, the toggle bit changes. In your 'basis' the toggle bit is always the same so your device thinks you are repeated the same command.

Next to that do you know the RC5 device address? In your 'basis' you use low-low-high-low-high to the device has address 0x05 which is a VCR so I assume you are controlling a VCR. If  not you should change 'basis'.

You can find the RC5 addresses on wikipedia.

For the rest it seems to be OK. One thing that can be a problem is the opto coupler. It will invert your bits and I do not know if the infrared received in your device does the same. If not then you should invert all bits in 'hoog' and 'laag'.

Kind regards,

Rob


Verzonden: woensdag 16 juni 2021 20:39
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] RC5 lib
 

hans

unread,
Jun 17, 2021, 2:21:03 PM6/17/21
to jallib
Hi Rob,
This was a testing way. I know abou the third bit . I am now working on a better way :
I am now so far that all commands are working beside the play function. (0x35) . On the normal button operation this button is also used as pauze command.
With the RC5 (0x35) command works only when i have the pauze situation activated with the button. Then it restarts, but not as a normal start.
In the program attached you can see the command list i have from this device.
If you have time pleas have a look at this revised, untested program change. :

alias RC5    is pin_D2
pin_D2_direction  = output
RC5 = low
var byte ADRES
var byte COMMAND

include delay                         -- fetch delay library
--
 procedure HOOG is
 RC5 = low
 _usec_delay(889)
 RC5 = high
  _usec_delay(889)
  end procedure
  
  procedure LAAG is
 RC5 = high
 _usec_delay(889)
 RC5 = low
  _usec_delay(889)
  end procedure
  
  procedure RC (byte in adres,byte in command) is
  
  var byte xx = adres <<3
  var byte yy = command <<2
  var bit x at xx : 7
  var bit y at yy : 7
 --start
  hoog
  hoog
  laag
  --now adres 5 bits
  for 5 loop
  if x == high then
  hoog
  else
  laag
  end if
  XX=XX << 1
  end loop
  -- now command 6 bits
   for 6 loop
  if y == high then
  hoog
  else
  laag
  end if
   yy = yy << 1
  end loop
  
  end procedure
  
  forever loop
  RC( 0x05, 0x35) -- play
  RC( 0x05, 0x36) -- stop
  RC( 0x05, 0x37) -- rec
  RC( 0x05, 0x32) --left
  RC( 0x05, 0x34)  --right
  RC( 0x05, 0x20)  --next
   RC( 0x05, 0x21) -- last
   RC( 0x05, 0x31)  -- delete
   RC( 0x05, 0x3c)  --lyrics
   RC( 0x05, 0x3a)  -- transp up
   RC( 0x05, 0x3b)  -- transp down
   RC( 0x05, 0x1d)  -- menu
   RC( 0x05, 0x29)  -- play next
   RC( 0x05, 0x22)  -- play last
   RC( 0x05, 0x3e)   -- monitor
   end loop
   
   regards
Hans

Op donderdag 17 juni 2021 om 19:47:23 UTC+2 schreef rob...@hotmail.com:

Rob CJ

unread,
Jun 18, 2021, 6:45:47 AM6/18/21
to jal...@googlegroups.com
Hi Hans,

The problem with the play button that also is pauze (when you press it again) can be related to the fact that you do not toggle the toggle bit so the VCR thinks you did not release the button.

So if you would declare a variable

var bit toggle = FALSE

And then change your procedure in (also add the delay at the end between two messages):

procedure RC (byte in adres,byte in command) is
  
  var byte xx = adres <<3
  var byte yy = command <<2
  var bit x at xx : 7
  var bit y at yy : 7
 --start
  hoog
  hoog

 -- Send and toggle the toggle bit
  if toggle then
     hoog
  else
     laag
  end if 
  toggle = !toggle

  --now adres 5 bits
  for 5 loop
  if x == high then
  hoog
  else
  laag
  end if
  XX=XX << 1
  end loop
  -- now command 6 bits
   for 6 loop
  if y == high then
  hoog
  else
  laag
  end if
   yy = yy << 1
  end loop
  
  -- And do not forget the space between messages
  delay_1mS(114)

  end procedure

Kind regards,

Rob


Verzonden: donderdag 17 juni 2021 20:21

hans

unread,
Jun 18, 2021, 1:45:10 PM6/18/21
to jallib
Hi Rob,
I have added the toggle part, ... same bad result, BUT now i set the RC to low at the end of the procedure, after the 114 ms delay... and it works.
Now i can spent this evening to get rid of my headache:

var bit toggle = FALSE

  RC5 = low

  end procedure



Op vrijdag 18 juni 2021 om 12:45:47 UTC+2 schreef rob...@hotmail.com:

Rob CJ

unread,
Jun 19, 2021, 3:25:01 AM6/19/21
to jal...@googlegroups.com
Hi Hans,

You are right, I completely missed that. At the end of the message you should have no signal ( in your case low). Good that you solved it.

Met vriendelijke groet,
Rob Jansen
Sent: Friday, June 18, 2021 7:45:10 PM

Rob CJ

unread,
Jun 19, 2021, 4:08:08 AM6/19/21
to jal...@googlegroups.com
Hi Hans,

Small addition. 'Officially' you should make the RC5 low before the repetition time of 114 ms so after the last bit of the message was sent.

Kind regards,

Rob


hans

unread,
Jun 19, 2021, 1:59:59 PM6/19/21
to jallib
Hi Rob, I'll do that. With the toggle now the play and pause are working also perfect. Thank for your help, great!!

Op zaterdag 19 juni 2021 om 10:08:08 UTC+2 schreef rob...@hotmail.com:
Reply all
Reply to author
Forward
0 new messages