Fun with IR Transmitter: Transmitting Sony SIRC protocol remote commands using TI Launchpad MSP-EXP430G2

Print Friendly

Simple code to transmit SONY remote control commands using Launchpad. The code can used to make your own IR Blaster. The code is not elegant but is certainly functional. This code would not have been possible without the lucid explanation about SONY SIRC protocol available at SB Projects informative web site.

Source Code

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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* ----------------------------------------------------------------------
* Encode Data to Sony SIRC remote protocol using MSP430 Microcontroller
* Coded by Ishan Karve (ishan at the rate gmail dot com)
* 26 Jan 2013
* Platform : TI MSP-EXP430G2 Launchpad running MSP430G2231
* Software Suite : Code Compose Studio, Version: 4.2.3.00004
* Note:
*
* IR Led is connected at port 1.0
* GND--<Res>---|<|--------P1.0
* Diode
* ----------------------------------------------------------------------
*/

#include "msp430g2452.h"
#define LED_OFF LED_OUT &= ~LED_0
#define LED_ON LED_OUT |= LED_0
#define LED_OUT P1OUT
#define LED_0 BIT0
#define LED_DIR P1DIR

void tx_wait(void);
void tx_start(void);
void tx_bit(short);
void tx_cmd(int);
void tx_adr(int);
void delay_ms(unsigned int ms)
{
while (--ms)
{
__delay_cycles(1000);
}
}

void main()
{
//stop watchdog
WDTCTL = WDTPW + WDTHOLD;

//setup internal DCO
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
//General GPIO Defines
LED_DIR |= LED_0; // Set P1.0 to output direction
LED_OUT &= ~LED_0; // Set the LEDs off

while(1)
{

tx_start();
tx_cmd(21);
tx_adr(1);
tx_wait();

}
}
void tx_wait()
{

//delay_ms(45);//
delay_ms(500);
}
void tx_cmd(int n)
{

int i=0;
int k=0;
for (i = 6; i >= 0; i--)
{
k=n%2;
n/=2;
tx_bit(k);
}

}
void tx_adr(int n)
{

int i=0;
int k=0;
for (i = 4; i >= 0; i--)
{
k=n%2;
n/=2;
tx_bit(k);
}

}

void tx_start()
{
int i;
for (i=0;i<96;i++)
{
//40 Khz Carrier generation. 25us pulse time
//9us On and 16us off
//96 pulses in one start bit time
LED_ON;
__delay_cycles(4);
LED_OFF;
__delay_cycles(8);
}
__delay_cycles(320); //600us delay
}
void tx_bit(short bitval) ///just makes a 1 to 0 and vice versa
{
int i=0;
switch (bitval)
{
case 0:
for (i=0;i<24;i++)
{
//40 Khz Carrier generation. 25us pulse time
//9us On and 16us off
LED_ON;
__delay_cycles(4);
LED_OFF;
__delay_cycles(8);
}
__delay_cycles(320); //600us delay
break;
case 1:
for (i=0;i<48;i++)
{
//40 Khz Carrier generation. 25us pulse time
//9us On and 16us off
LED_ON;
__delay_cycles(4);
LED_OFF;
__delay_cycles(8);
}
__delay_cycles(320); //600us delay
break;
}

}

Download Project Source

Ishan Karve

About Ishan Karve

Ishan Karve is just an every day normal guy next door who happens to be an Electronics Engineer by profession and dabbles with PHP, Javascript, C++ and python. His interests vary as seasons change.. they change from astronomy to soul searching. This site is just a reflection of what he does to keep his mind engaged when he is not occupied by work and family. He is an extremely objective guy and is always ready for some good arguments.. of course over a glass of 40% proof alcohol.
This entry was posted in DIY, MSP430, Projects and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *