www.eXtremeElectronics.co.in

IR Remote Interfacing

xBoard v2.0

Easy to Use learning and development tool for Atmel AVR family of MCUs.

 

<< Return To Help Index

All of us must have used IR remote control of our TV and praise the comfort they provide. IR remote controls have become very popular these days, they comes with DVD players,ACs and many consumer electronics item. If we can use one with our own project its like dream come true !

With xBoard series of single board computer, you can very easily interface with these IR remote controls. The board has integrated IR receiver and we have made a very easy to use C library to work with them. Even a beginner can control his/her project with Remote !!!

A Typical DVD player remote shipped with xBoard™ v2.0

 

IR Receiver on xboard (TSOP1738)

Onboard IR Receiver.

 

Setup

Short JUPMER JP1 to use IR Receiver.

Programming.

To add IR Remote support in your project follow the steps –
STEP1: Create a New project in AVRStudio (WinAVR C Project)
STEP2: Copy


“remote.c”
“remote.h”
“rckey.h”


to your project folder. These file are present inside the folder "xAPI" in the support CD.
STEP3: Add all the files to your project. (How To add file to your project is described here)
STEP4: Configure the project for 16MHz Crystal Frequency. This step is detailed here.
STEP5: Call RemoteInit(); Function at program startup.

And you are done !!!

To get the key code of key pressed in Remote Call

GetRemoteCmd();

The details of function is given below.

Function :

unsigned char GetRemoteCmd(char wait)

Description:
This function is used to get commands from the remote control.It returns the key code of the key pressed in the remote control.

Parameters/Arguments required:

char wait [0 or 1]

If wait=0 function returns immediately and returns key code of key pressed or RC_NONE if no key is pressed. Otherwise if wait=1 function waits for the user to press a key. Function returns only if user presses a key.

Return Value:
Key Code of the key pressed.

Every key in remote has a unique number between 0-255. And this function returns this value. There are some predefined constants for some keys. For example in the remote shown above the UP KEY has code 74. It is defined in “rckeys.h” file. So to check if UP key is pressed you can write RC_UP instead of 74.

Some other constants

RC_UP
RC_DOWN
RC_LEFT
RC_RIGHT
RC_ENTER

Sample Code.

Now we will write a simple program which will wait till a key is pressed on remote. Then it will show the KEYCODE of the key pressed.


/*********************************************************************

                 xBoard(TM) v2.0 Sample Programs

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


Description :  To demonstrate the use of IR remote control
            Interface API Functions. Press any of key on 
            Remote control and LCD will show its KEY CODE.

      

NOTE: To RUN this demo
      *LCD Must be connected.
      *JP1 Must be connected.

Author      : Avinash Gupta 2008
Web         : www.eXtremeElectronics.co.in
                   
**********************************************************************/

#include <avr/io.h>

#include "lcd.h"
#include "remote.h"

void main()
{
   uint8_t remote_command=0;  //The key code of key pressed

   //Initialize LCD System
   LCDInit(LS_BLINK);

   //Clear LCD
   LCDClear();

   //Initialize Remote System.
   RemoteInit();

   while(1)
   {

      LCDClear();
      LCDWriteString("xBoard R/C TST");
      LCDWriteStringXY(0,1,"Key Code:");
      LCDWriteInt(remote_command,3);


      remote_command=GetRemoteCmd(1);  //Wait for a key press

   }


}

PROJECT FILE - Find the complete project in “Sample” folder in Support Disk. Load the “RemoteTest.aps” file by double clicking on it.
HEX FILE - Find hex file “RemoteTest.HEX” inside folder “HEX” in Support Disk.

See Also:

<< Return To Help Index