GaganP:
I have a Panasonic Viera 42AS610 and I want to use an Arduino Mega 2560 for cloning the remote. 
OK here it is:
///////////////////////////////////////////////////////////////////////////////
//
// Infrared Remote Control for Panasonic Plasma TV
// Copyright (c) 2015 Roger A. Krupski <rakrupski@verizon.net>
//
// Last update: 16 September 2015
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////
#define F_CPU 8000000UL
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/pgmspace.h>
#include <util/delay.h> // for _delay_xs
// ATtiny25 fuse settings:
// H-fuse: 0xDF (SPI enabled, BOD disabled)
// L-fuse: 0xFF (external crystal)
// E-fuse: 0xFF (self program enabled)
#define IO_PORT PORTB // (port write)
#define IO_PIN PINB // (port read)
#define IO_DDR DDRB // (port ddr)
#define IR_BIT PB0 // 2N4401 base drive for IR LED (thru 150 ohm resistor)
#define MODE PB1 // select mode: (currently unused) (has external 10K pullup)
#define BUTTON PB2 // send IR code (red button - active low - external 10K pullup)
#define KHZ 40 // IR carrier freq
volatile uint8_t count = 0; // led pulse counter
volatile uint8_t state = 0; // led on/off state
volatile uint8_t onoff = 0; // pulse polarity
// Panasonic TV power toggle
static const uint8_t panapower[] PROGMEM = {
// header
0x7e, 0x3f,
// address
0x12, 0x0e, 0x12, 0x2a, 0x12, 0x0e, 0x12, 0x0e, // 4
0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, // 0
0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, // 0
0x12, 0x0e, 0x12, 0x2a, 0x12, 0x0e, 0x12, 0x0e, // 4
// command
0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, // 0
0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, 0x12, 0x2a, // 1
0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, // 0
0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, 0x12, 0x0e, // 0
0x12, 0x2a, 0x12, 0x0e, 0x12, 0x2a, 0x12, 0x2a, // B
0x12, 0x2a, 0x12, 0x2a, 0x12, 0x0e, 0x12, 0x0e, // C
0x12, 0x2a, 0x12, 0x0e, 0x12, 0x2a, 0x12, 0x2a, // B
0x12, 0x2a, 0x12, 0x2a, 0x12, 0x0e, 0x12, 0x2a, // D
// footer
0x12, 0x0e,
// end of command
0x00,
};
void send_cmd (const uint8_t *cmd, uint8_t rpt, uint8_t dly)
{
uint8_t x;
IO_DDR |= _BV (IR_BIT); // IR drive pin is an output
state = 0; // insure state starts correctly
while (rpt--) {
x = 0; // start PROGMEM address offset
do { // each one is a pulse count at 40 khz
while (count); // wait until ISR is done sending pulses
count = pgm_read_byte (cmd + x++); // set next pulse count
onoff = (x % 2); // set which side is high
} while (count); // until we hit 0x00 (end of command)
_delay_ms (dly); // delay between commands
}
IO_DDR &= ~_BV (IR_BIT); // turn off IR drive pin
}
ISR (TIMER0_COMPA_vect)
{
if (count) { // if a count was pushed in...
// if LED is on then turn it off
// turn it on, or leave it off, depending on the state of "onoff"
state ? IO_PORT &= ~_BV (IR_BIT) : onoff ? IO_PORT |= _BV (IR_BIT) : IO_PORT &= ~_BV (IR_BIT);
// decrement count (on times only)
count-= state;
// toggle LED on/off state
state ? state = 0 : state = 1;
}
}
ISR (INT0_vect) // INT0 handler - we arrive here when the button is pressed
{
GIMSK &= ~_BV (INT0); // disable hardware INT0
cli (); // ignore further interrupts
}
int main (void)
{
uint8_t deb;
cli (); // disable interrupts while setting stuff
IO_PORT &= ~(_BV (IR_BIT) | _BV (MODE) | _BV (BUTTON)); // set all ports low
IO_DDR &= ~(_BV (MODE) |_BV (BUTTON)); // set port DDR to inputs
ADCSRA &= ~_BV (ADEN); // turn off ADC
sleep_bod_disable (); // turn off brown-out detector
set_sleep_mode (SLEEP_MODE_PWR_DOWN); // set CPU to go into power down mode
MCUCR &= ~(_BV (ISC01) | _BV (ISC00)); // set hardware INT0 active on low level
sleep_enable (); // enable CPU to be powered down
// set timer 0 (8 bit) to CTC mode, 40 khz.
// this generates the IR pulses
TCCR0A = _BV (WGM01); // mode 2 (CTC) OCR0A = top
TCCR0B = _BV (CS00); // F_CPU/1 = 8000000
OCR0A = ((F_CPU/2000/KHZ)-1); // divider for IR carrier freq 40 khz.
TIMSK = _BV (OCIE0A); // enable interrupt on OCR0A match
while (1) {
GIMSK |= _BV (INT0); // enable INT0 active low
sei (); // enable interrupts so cpu can recognize pushbutton INT
sleep_cpu (); // power down cpu (all clocks stopped)
// cpu is now asleep - we are waiting for INT0...
// ...we are here when the button is pushed
sei (); // enable interrupts (coming out of sleep disabled them)
deb = 200; // init debounce
while (deb--) {
_delay_us (50); // 50 us delay
if (IO_PIN & _BV (BUTTON)) { // if button bounced...
deb = 200; // ...reset debounce
}
} // now button has been bounce-free for 10000 usec (10 msec)
// now send IR command and go back to sleep
send_cmd (0, 1, 1); // command offset 0, send it once, delay unused
deb = 200; // init debounce
while (deb--) {
_delay_us (50); // 50 us delay
if (! (IO_PIN & _BV (BUTTON))) { // if button bounced...
deb = 200; // ...reset debounce
}
} // now button has been bounce-free for 10000 usec (10 msec)
}
}
Feeling a bit overwhelmed? 