Sei sulla pagina 1di 4

10/31/2014 RC5 Protocol Decoding with 8051 microcontroller (Embedded C) | ProEmbSys Technologies

http://blog.proembsys.in/rc5-protocol-decoding-with-8051-microcontroller-embedded-c/ 1/5
By ProEmbSys Technologies, | August 7, 2013 3 Comments
RC5 Protocol Decoding with 8051 microcontroller
(Embedded C)
RC5 Protocol Decoding with 8051 microcontroller :-
Details :
About Infrared:
Infrared light is electromagnetic radiation with longer wavelengths than those of visible light. Infrared
light is used in industrial, scientic, and medical applications. Most of the remote controllers use IR light to
send information.
RC5 Protocol:
This protocol was developed by Phillips using Manchester Encoding. Information is sent in frames, where
each frame is consist of 14 bits. First two bits are start bits, the next bit is ip bit, which toggles every next
frame if same command is sent. Next ve bits are system address (remote specic) bits and last 6 bits are
command bits, which actually stores command. Each bit is of 64 IR pulses.
RC5 Protocol Frame:
Manchester Encoding:
Every bit in an RC5 transmission has uniform duration, and contains one transition. 0 is encoded by a high
to low transition, and a 1 by a low to high transition. There is a transition in the middle of the bit. So bit
containing 0 value will be encoded as rst 32 high pulses and next 32 low pulses, while 1 will be
represented by rst 32 low pulses and next 32 high pulses.
An Example:
10/31/2014 RC5 Protocol Decoding with 8051 microcontroller (Embedded C) | ProEmbSys Technologies
http://blog.proembsys.in/rc5-protocol-decoding-with-8051-microcontroller-embedded-c/ 2/5
Lets consider a remote controller with 38kHz frequency output,
T= 1/38,000=0.000026316 26s
Now each bit consists of 64 IR bits,
64 pulses x 26s = 1664s = 1.664ms
So total time for a protocol frame is
14 x 1.664 = 23.24 ms
Decoding with 8051:
We have used TSOP1738 sensor to decode RC5 protocol, this sensor gives active low output, so 0
received is rst 32 pulses low and next 32 high. The out pin of TSOP1738 is connected to interrupt source
of 8051, decoding can be done in both ways, either polling or interrupt based,
Here we will consider interrupt based mechanism, so when it will receive a rst start bit (i.e. 1, start bits
are always 1 in RC5), it will be rst 32 pulses high, and next will be low, here interrupt will occur, to decode
information we can skip start and ip bit, i.e. MCU should skip 2.75 bits, so after an interrupt wait for
4.57ms to get next bit.
Here comes decoding of the next 5 system address bits, which holds the address of remote controller,
here after each bit time i.e. 1.664ms , MCU gets value of OUT pin and stores in a variable. Same way the
next six bits are decoded and command value is calculated from protocol frame.
Components :
MCU: P89v51RD2(8051 Core)
Remote Controller: RC5 (Phillips TV remote controller)
162 LCD Display to display commands and addresses.
IR Sensor : TSOP1738
Circuit Diagram / Schematic:
10/31/2014 RC5 Protocol Decoding with 8051 microcontroller (Embedded C) | ProEmbSys Technologies
http://blog.proembsys.in/rc5-protocol-decoding-with-8051-microcontroller-embedded-c/ 3/5
Embedded C code for RC5 protocol decoding:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
sbit ir=P3^2;
unsigned char i,bitCount;
char *str,addr,cmd,temp;
void RC5_Decode()
{
addr=0x00;
cmd=0x00;
while(ir);
for(i=255;i>0;i--);
for(i=255;i>0;i--);
for(i=255;i>0;i--);
for(i=255;i>0;i--);
for(i=255;i>0;i--);
for(i=114;i&gt;0;i--);</code>

for(bitCount=0;bitCount&lt;5;bitCount++)
{
for(i=255;i&gt;0;i--);
for(i=255;i&gt;0;i--);
for(i=255;i&gt;0;i--);
for(i=4;i&gt;0;i--);

if(!ir)
addr|=(1&lt;&lt;bitCount);
}

for(bitCount=0;bitCount&lt;6;bitCount++)
{
10/31/2014 RC5 Protocol Decoding with 8051 microcontroller (Embedded C) | ProEmbSys Technologies
http://blog.proembsys.in/rc5-protocol-decoding-with-8051-microcontroller-embedded-c/ 4/5
Related Posts:
1. Microcontroller based LED Mood Lamp
2. 8051 microcontroller based Intelligent Home Automation System
3. Online Monitoring System of Temperature of Conductors and Fittings Based On GSM SMS and
Zigbee
4. 8051 Microcontroller Based Mini Project List
Category: Embedded Tags: 16x2 LCD display , 8051, Embedded C, Embedded Systems , IR sensor ,
Microcontrollers , P89V51RD2, RC5, RC5 Protocol , TSOP1738
3 thoughts on RC5 Protocol Decoding with 8051 microcontroller (Embedded C)
I need a refrence code for decoding RC5 protocol.. please help me.. coz while i Rutvik
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
for(i=255;i&gt;0;i--);
for(i=255;i&gt;0;i--);
for(i=255;i&gt;0;i--);
for(i=4;i&gt;0;i--);

if(!ir)
cmd|=(1&lt;&lt;bitCount);
}
cmd=~cmd;
cmd=(cmd &amp; 0x3f);
temp=0;
for(bitCount=0;bitCount&lt;6;bitCount++)
{
if( cmd &amp; (1&lt;&lt;bitCount))
{
temp=(temp |(1&lt;&lt;5-bitCount));
}

}
cmd=temp;

addr=~addr;
addr=(addr &amp; 0x1f);
temp=0;
for(bitCount=0;bitCount&lt;5;bitCount++)
{
if( addr &amp; (1&lt;&lt;bitCount))
{
temp=(temp |(1&lt;&lt;4-bitCount));
}

}
addr=temp;
}

Potrebbero piacerti anche