View Full Version : need help in decoding RC-5 IR-remote
vu2iia
- 11th August 2007, 17:10
Hi All,
I need some help in decoding RC-5 IR remote, can somebody help me in getting started with some simple example code as I am still novice. I plan to use pic16f72. I searched forum but did not find sufficient info to start.
Any help would be much appreciated especially with sample code to start.
Thanks in advance
vu2iia
www.vu2iia.blogspot.com
Ioannis
- 13th August 2007, 08:32
Take a look at:
http://www.picbasic.co.uk/forum/showthread.php?t=1328
http://www.picbasic.co.uk/support/Article.pdf
http://www.picbasic.co.uk/forum/showthread.php?t=6492
to name a few. More if you do a search on the forum...
Ioannis
vu2iia
- 14th August 2007, 04:34
Thank you Ioannis for you help.
Below is the modified code from Proton to PBP. I made very minor changes and it works very well. Novice may do the modification to suit their needs. Its not my original work.
Original code is available at http://www.picbasic.nl/indexes_uk.htm
modified code is given below.It may contain some unwanted lines ignored.
Code below shows DEC key values on 2x16 LCD. Modify code to suit
PIC of your choice.
************************************************** ***********
'Device pic16f72, Its very cheap
define osc 4
DEFINE LCD_DREG PORTB 'LCD data port
DEFINE LCD_DBIT 4 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTB 'LCD register select port
DEFINE LCD_RSBIT 3 'LCD register select bit
DEFINE LCD_EREG PORTB 'LCD enable port
DEFINE LCD_EBIT 2 'LCD enable bit
DEFINE LCD_RWREG PORTB 'READ/WRITE SELECT PORT
DEFINE LCD_RWBIT 1 'READ/WRITE SELECT BIT
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
PAUSE 500
lcdout $fe,1,"LCD OK"
pause 500
ALL_DIGITAL
ADCON1 = 7 'disable A/d work digital
;Normal aliases (constants)
Glitch con 52 ;Max 255: Reduction glitches
SYMBOL LED_Time = 500 ;mSec: Error LED's burning time
Ok con 50 ;Max 255: Controltime of the RC5 code is received ok
;Port aliases
IR_Receiver var PORTA.4 ;TSOP1736
ByName var PORTB.0 ;When low the IR-code is given else (unconnected) the System-name and Command-name
; 76543210
TRISA = %11110000
;BYTE
Command VAR BYTE
CommandOld VAR BYTE
Systeem VAR BYTE
SysteemOld VAR BYTE
BD1 VAR BYTE ;Byte Dummy
;BIT
ByNameOld VAR BIT ;When switching between code- and text-mode and sending the same RC5 code then should the LCD not been updated
ToggBit VAR BIT
Value VAR BIT
' ID1 VAR BIT ;bIt Dummy
CLEAR
GOTO Start
;Subroutines
BitOphalen:
Value = IR_Receiver ;Make value 0 or 1 dependent from received IR-code
BD1 = 0
WHILE IR_Receiver = Value AND BD1 < Ok;Level must change within time 'Ok'
BD1 =bd1+1
WEND
IF Ok = BD1 THEN ErrorReceive ;No level-change whitin the 'Ok' time
pauseUS 1100 ;950 - 1600
RETURN
;Mainprogram
Start:
ByNameOld = ByName
BD1 = 0
WHILE IR_Receiver = 1
WEND ;Wait until a IR-signal is received
WHILE IR_Receiver = 0
if BD1 < Glitch then BD1 =bd1+1 'Glitch val 52
WEND
IF BD1 < Glitch THEN GOTO ErrorGlitch
CommandOld = Command ;Save old values for repair in case of a error
SysteemOld = Systeem
pauseUS 500 ;200 - 825; Avoid RC5 header
GOSUB BitOphalen
Command.6 = Value ^ 1 ;Extended bit
GOSUB BitOphalen
ToggBit = Value
GOSUB BitOphalen
Systeem.4 = Value
GOSUB BitOphalen
Systeem.3 = Value
GOSUB BitOphalen
Systeem.2 = Value
GOSUB BitOphalen
Systeem.1 = Value
GOSUB BitOphalen
Systeem.0 = Value
GOSUB BitOphalen
Command.5 = Value
GOSUB BitOphalen
Command.4 = Value
GOSUB BitOphalen
Command.3 = Value
GOSUB BitOphalen
Command.2 = Value
GOSUB BitOphalen
Command.1 = Value
GOSUB BitOphalen
Command.0 = Value
lcdout $fe,1
lcdout $fe,$80,"Sys:", DEC Systeem
lcdout $fe,$c0,"Com:", DEC Command
pause 100
goto start
ErrorGlitch:
'original ckt has LED to indicate error, but I have not used.
'Receive error (No RC5 code or glitch) ' not used
'pause LED_Time ' not used
GOTO Start
ErrorReceive:
Command = CommandOld ;Repair Command and Systeem
Systeem = SysteemOld
GOTO Start
************************************************** **************
Thanks
vu2iia
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.