Difference between revisions of "Avr rc5 remote control"

From Electriki
Jump to navigationJump to search
(AVR (ATMega 16), Philips RC5 Remote Control, Example code in C)
 
m (Fixed broken link)
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
__NOEDITSECTION__
 
__NOEDITSECTION__
[[category:projects]]
+
[[category:projects done]]
  
== Introduction ==
+
==Introduction==
 +
[[Image:Stk500_tsop1736_rc5_quick_and_dirty_picture.jpg|thumb|'''The test setup'''
 +
Just a quick snapshot of the test setup. An STK500 cruedly interfaced to a TSOP1736 soldered on a recycled prototype pcb.]]
 +
[[Image:Avrrc5rev11.png|thumb|'''Minimum circuit''']]
  
Interfacing a standard Philips RC5 protocol remote control to an AVR is easy. It doesn't take neither much hardware nor code to do so. I've found that there is an official application note from Atmel describing how to do this. Atmels example is done in assembler and is fault tolerant, but it's difficult to understand. By doing it in C it becomes very simple and understandable.
+
Interfacing a standard Philips RC5 protocol remote control to an Atmel AVR should be easy. It shouldn't have to take neither much hardware nor code to do so. I've found that there is an official application note from Atmel describing how to do this. Atmels example is done in assembler and is fault tolerant, but it's difficult to understand. By doing it in C it becomes very simple and understandable.
 +
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  
 
+
==The RC5 protocol==
== The Code ==
+
[[Image:Philips_remote_control.jpg|thumb|'''The Remote Control'''
 
+
A worn Philips remote control used for testing.]]
<pre>
+
I'm not going to provide you with my own version of how it works.<br>
 +
I suggest you read this: http://www.sbprojects.com/knowledge/ir/rc5.php<br>
 +
That link also has a list of the command and address codes that you'll need.
 +
<br><br><br><br><br><br><br><br><br>
 +
 +
==The Code==
 +
The stripped down C code:
 +
<syntaxhighlight lang="c">
 
#include <avr/interrupt.h>
 
#include <avr/interrupt.h>
 
#include <avr/io.h>
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include <util/delay.h>
 
void init_int0()
 
{
 
// Interrupt on INT0 pin going low
 
MCUCR = (1 << ISC01);
 
 
// Turn on INT0!
 
GICR |= (1 << INT0);
 
}
 
  
 
typedef union {  
 
typedef union {  
Line 33: Line 35:
 
};
 
};
 
} rc5data;
 
} rc5data;
 
  
 
static volatile int flag = 0;
 
static volatile int flag = 0;
 
static volatile rc5data data;
 
static volatile rc5data data;
 +
 +
void init_int0()
 +
{
 +
// Interrupt on INT0 pin going low
 +
MCUCR = (1 << ISC01);
 +
 +
// Turn on INT0!
 +
GICR |= (1 << INT0);
 +
}
  
 
SIGNAL (INT0_vect)
 
SIGNAL (INT0_vect)
Line 45: Line 55:
 
data.raw = 0;
 
data.raw = 0;
  
// triggers on faling edge of start bit 1.
+
// triggers on falling edge of start bit 1.
 
_delay_ms(0.2);
 
_delay_ms(0.2);
  
Line 61: Line 71:
 
{
 
{
 
init_int0();
 
init_int0();
sei(); // Enable interrupts
+
sei(); // Enable interrupts
  
 
while(1) {
 
while(1) {
Line 73: Line 83:
 
return 0;
 
return 0;
 
}
 
}
</pre>
+
</syntaxhighlight>
 +
 
 +
==External Links==
 +
*[http://www.atmel.com/dyn/resources/prod_documents/doc1473.pdf Application Note AVR410: RC5 IR Remote Control Reciever]

Latest revision as of 11:06, 7 April 2012


Introduction

The test setup Just a quick snapshot of the test setup. An STK500 cruedly interfaced to a TSOP1736 soldered on a recycled prototype pcb.
Minimum circuit

Interfacing a standard Philips RC5 protocol remote control to an Atmel AVR should be easy. It shouldn't have to take neither much hardware nor code to do so. I've found that there is an official application note from Atmel describing how to do this. Atmels example is done in assembler and is fault tolerant, but it's difficult to understand. By doing it in C it becomes very simple and understandable.

















The RC5 protocol

The Remote Control A worn Philips remote control used for testing.

I'm not going to provide you with my own version of how it works.
I suggest you read this: http://www.sbprojects.com/knowledge/ir/rc5.php
That link also has a list of the command and address codes that you'll need.








The Code

The stripped down C code: <syntaxhighlight lang="c">

  1. include <avr/interrupt.h>
  2. include <avr/io.h>
  3. include <util/delay.h>

typedef union { uint16_t raw; struct { unsigned cmd : 6; // LSB unsigned addr : 5; unsigned toggle : 1; unsigned start : 2; unsigned : 2; // MSB }; } rc5data;

static volatile int flag = 0; static volatile rc5data data;

void init_int0() { // Interrupt on INT0 pin going low MCUCR = (1 << ISC01);

// Turn on INT0! GICR |= (1 << INT0); }

SIGNAL (INT0_vect) { int pos = 0;

if (!flag) { data.raw = 0;

// triggers on falling edge of start bit 1. _delay_ms(0.2);

while (pos < 14) { data.raw = (data.raw << 1) | ((~PIND & 0x04) >> 2); _delay_ms(1.8); pos++; }

flag = 1; } }

int main() { init_int0(); sei(); // Enable interrupts

while(1) {

while(!flag);

// Do with data from the remote control here what you like. flag = 0; }

return 0; } </syntaxhighlight>

External Links