Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,253
// Receive Sony IR Remote signals using PIC12F675
// internal oscillator 4MHz (make sure it is calibrated), watchdog disabled
// connect 3-pin IR receiver module to GPIO 0 input
// Sony TV remote will toggle:
// GPIO 1 output for TV '1' button
// GPIO 2 output for TV '2' button
// GPIO 4 output for TV '3' button
// GPIO 5 output for TV '4' button
// all outputs off for TV '0' button
// all outputs on for TV '9' button
sbit ir_rx at GPIO.B0; // IR receiver 40KHz
// function prototypes
void get_mark_time(void); // get Sony IR mark time
// global variables
unsigned char counter = 0;
unsigned char shadow = 0;
unsigned char bitcount;
unsigned char ir_address;
unsigned char ir_command;
unsigned int mark_time;
void interrupt()
{
if (INTCON.T0IF)
{
counter++; // increment counter
INTCON.T0IF = 0; // Clear Timer0 overflow interrupt flag
}
}
void main()
{
CMCON = 7; // disable comparator
ANSEL = 0; // disable analogue
OPTION_REG = 0x03; // TMR0 prescaler set to 1:16
TRISIO = 0x01; // IR b0 = input, rest output
GPIO = 0; // all outputs off
// start timer 0 counting
INTCON.GIE = 1; // Global interrupt enable
INTCON.T0IE = 1; // Enable Timer0 overflow interrupt
while(1)
{
ir_command = 0; // initialise to prevent false trigger
ir_address = 0; // initialise to prevent false trigger
get_mark_time(); // get Sony leader - 2.4mS Mark, 1.2mS space
if ((mark_time > 0x80) && (mark_time < 0xB0))
{ // ignore anything but 2.4mS mark
for(bitcount = 0 ; bitcount < 7 ; bitcount++)
{ // 7 bit command
get_mark_time(); // get a Sony IR bit
ir_command >>= 1; // shift
ir_command &= 0x7f; // top bit zero
if (mark_time > 0x40)
{ // > 40 is assumed to be a 1
ir_command ^= 0x80; // top bit 1
}
}
ir_command >>= 1; // shift 1 unused bit
ir_command &= 0x7F; // clear top bit
for(bitcount = 0 ; bitcount < 5 ; bitcount++)
{ // 5 bit address
get_mark_time(); // get a Sony IR bit
ir_address >>= 1; // shift
ir_address &= 0x7f; // top bit zero
if (mark_time > 0x40)
{
ir_address ^= 0x80; // top bit 1
}
}
ir_address >>= 3; // shift 3 unused bits
ir_address &= 0x1F; // clear top 3 bits
}
if(ir_address == 1)
{ // TV
if(ir_command == 0)
{ // button 1
// toggle output 1
GP1_bit = ~GP1_bit;
}
if(ir_command == 1)
{ // button 2
// toggle output 2
GP2_bit = ~GP2_bit;
}
if(ir_command == 2)
{ // button 3
// toggle output 4
GP4_bit = ~GP4_bit;
}
if(ir_command == 3)
{ // button 4
// toggle output 5
GP5_bit = ~GP5_bit;
}
if(ir_command == 8)
{ // button 9
// all outputs on
GPIO = 0xFF;
}
if(ir_command == 9)
{ // button 0
// all outputs off
GPIO = 0x00;
}
Delay_ms(200); // avoid double toggle
}
}
}
// get time of mark, then ignore space
void get_mark_time(void)
{
while(ir_rx); // wait for a mark
counter=0;
TMR0 = 0;
while(!ir_rx); // wait for space
mark_time = (counter << 8) + TMR0; // collect integer mark time
}
Yes............ Finally I've made it possible.
here is the modified code.....
Code:// Receive Sony IR Remote signals using PIC12F675 // internal oscillator 4MHz (make sure it is calibrated), watchdog disabled // connect 3-pin IR receiver module to GPIO 0 input // Sony TV remote will toggle: // GPIO 1 output for TV '1' button // GPIO 2 output for TV '2' button // GPIO 4 output for TV '3' button // GPIO 5 output for TV '4' button // all outputs off for TV '0' button // all outputs on for TV '9' button sbit ir_rx at GPIO.B0; // IR receiver 40KHz // function prototypes void get_mark_time(void); // get Sony IR mark time // global variables unsigned char counter = 0; unsigned char shadow = 0; unsigned char bitcount; unsigned char ir_address; unsigned char ir_command; unsigned int mark_time; void interrupt() { if (INTCON.T0IF) { counter++; // increment counter INTCON.T0IF = 0; // Clear Timer0 overflow interrupt flag } } void main() { CMCON = 7; // disable comparator ANSEL = 0; // disable analogue OPTION_REG = 0x03; // TMR0 prescaler set to 1:16 TRISIO = 0x01; // IR b0 = input, rest output GPIO = 0; // all outputs off // start timer 0 counting INTCON.GIE = 1; // Global interrupt enable INTCON.T0IE = 1; // Enable Timer0 overflow interrupt while(1) { ir_command = 0; // initialise to prevent false trigger ir_address = 0; // initialise to prevent false trigger get_mark_time(); // get Sony leader - 2.4mS Mark, 1.2mS space if ((mark_time > 0x80) && (mark_time < 0xB0)) { // ignore anything but 2.4mS mark for(bitcount = 0 ; bitcount < 7 ; bitcount++) { // 7 bit command get_mark_time(); // get a Sony IR bit ir_command >>= 1; // shift ir_command &= 0x7f; // top bit zero if (mark_time > 0x40) { // > 40 is assumed to be a 1 ir_command ^= 0x80; // top bit 1 } } ir_command >>= 1; // shift 1 unused bit ir_command &= 0x7F; // clear top bit for(bitcount = 0 ; bitcount < 5 ; bitcount++) { // 5 bit address get_mark_time(); // get a Sony IR bit ir_address >>= 1; // shift ir_address &= 0x7f; // top bit zero if (mark_time > 0x40) { ir_address ^= 0x80; // top bit 1 } } ir_address >>= 3; // shift 3 unused bits ir_address &= 0x1F; // clear top 3 bits } if(ir_address == 1) { // TV if(ir_command == 0) { // button 1 // toggle output 1 GP1_bit = ~GP1_bit; } if(ir_command == 1) { // button 2 // toggle output 2 GP2_bit = ~GP2_bit; } if(ir_command == 2) { // button 3 // toggle output 4 GP4_bit = ~GP4_bit; } if(ir_command == 3) { // button 4 // toggle output 5 GP5_bit = ~GP5_bit; } if(ir_command == 8) { // button 9 // all outputs on GPIO = 0xFF; } if(ir_command == 9) { // button 0 // all outputs off GPIO = 0x00; } Delay_ms(200); // avoid double toggle } } } // get time of mark, then ignore space void get_mark_time(void) { while(ir_rx); // wait for a mark counter=0; TMR0 = 0; while(!ir_rx); // wait for space mark_time = (counter << 8) + TMR0; // collect integer mark time }
And its working.....
is button 1 & so allcommand == 0
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?