Thursday, September 17, 2009

IR Remote Control

prototype circuit:
single-button (single-function) mini-Remote Control for Sony TV




Hi-Tech C code:
 // Sony Remote Control  
// 12-bit SIRC protocol
// Hi-Tech C code by yus
// rev 1 Oct 28, 2008
#include <pic.h>
__CONFIG(XT & WDTDIS & PWRTEN & BORDIS & UNPROTECT);
#define irled PORTA //IR-LED pin
#define irled_tris TRISA //tri-state
//devices
#define tv 1
#define vcr1 2
#define vcr2 3
#define laser_disc_unit 6
#define surround_sound 12
#define cassette_deck 16
#define cd_player 17
#define equalizer 18
//functions
#define key_1 0
#define key_2 1
#define key_3 2
#define key_4 3
#define key_5 4
#define key_6 5
#define key_7 6
#define key_8 7
#define key_9 8
#define key_0 9
#define channel_up 16
#define channel_down 17
#define volume_up 18
#define volume_down 19
#define mute 20
#define power 21
#define reset 22
#define audio_mode 23
#define contrast_up 24
#define contrast_down 25
#define colour_up 26
#define colour_down 27
//#define channel_lock 28
#define brightness_up 30
#define brightness_down 31
//#define hue_down 32
//#define hue_up 33
//#define sharpness_up 34
//#define sharpness_down 35
//#define recall 36
//#define tv_video 37
#define balance_left 38
#define balance_right 39
//#define equalizer 40
//#define surround 41
#define standby 47
void burst(unsigned int pulses)
{
do //~40kHz, 1/3 duty cycle
{
irled = 0xff;
NOP(); NOP(); NOP();
NOP(); NOP(); NOP(); //@4MHz xtal
irled = 0x00;
NOP(); NOP(); NOP();
NOP(); NOP(); NOP();
}while(--pulses);
}
void space(unsigned int interval)
{
do{
NOP(); NOP(); NOP();
NOP(); NOP(); NOP();
NOP(); NOP(); NOP();
NOP(); NOP();
}while(--interval);
}
void remote_control(unsigned int function, unsigned int device) //~45ms frame
{
unsigned int i, time;
burst(96); //header
space(24);
time = 10; // count the time duration
for(i=0; i<7; i++) //7-bit command/funtion
{ //LSB first
if(function&(1<<i))
{
burst(48); space(24); //logic "1"
time = time + 6; //increment counter
}
else
{
burst(24); space(24); //logic "0"
time = time + 4; //increment counter
}
}
for(i=0; i<5; i++) //5-bit address (device address)
{ //LSB first
if(device&(1<<i))
{
burst(48); space(24); //logic "1"
time = time + 6; //increment counter
}
else
{
burst(24); space(24); //logic "0"
time = time + 4; //increment counter
}
}
space((150-time)*12); // blanking time, complete the 45ms frame
}
//sample main function
void main()
{
irled_tris = 0x00; //as output pin
irled = 0x00; // initial state
while(1)
{
remote_control(power,tv); // power on/off a TV set
//burst(255);
}
}
*tested only with Sony Trinitron (model#: KV-SW212N50)

1 comment: