Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Self learning IR transmitter

Status
Not open for further replies.

cebrax

Newbie level 6
Joined
Apr 24, 2009
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,348
Hey all,
I want to make a self learning infrared transceiver that learns every infrared code.
I know, it sounds like I want to step too many ladders.. But is possible right?

I am using Mikroelektronika mikroC PRO for PIC compiler.

Here is my code so far, but I am totally lost.

Any help?

Code:
bit infrared,buffer,change,j;
unsigned char measure=0,ref1=0,timepassed;
volatile unsigned char i=0;
void interrupt()
{
 if(INTCON.T0IF)
 {
  measure++;
  TMR0=0;
  INTCON.T0IF=0;
 }
}
void main(){
    unsigned char measuretxt[7];
    ANSEL = 0; // Configure AN pins as digital I/O
    ANSELH = 0;
    PORTB = 0;
    PORTC = 0;
    PORTD = 0;
    TRISB = 0;
    TRISC = 0;
    TRISD = 0x01;
    OPTION_REG=0x80;
    TMR0=0;
    INTCON.T0IE=1;
    INTCON.GIE=1;
    j=0;
    buffer=0;
    while(1)
    {
     infrared=~PORTD.F0;
     if(buffer==infrared) change=0;
     else
     {
      change=1;
      buffer=infrared;
     }
     /*
         |-----|    |-----|    |-----|
         |     |    |     |    |     |
     ____|     |____|     |____|     |____
     
     */
     if(change)
     {
      if(!j){ ref1=measure; j=1; }
      else{ timepassed=measure-ref1;
            ref1=measure;
           }
      EEPROM_Write(0x00+i,timepassed);
      i++;
     }
    }
}
 

anyone has a c code example?
 

Hi all,
What about self learning RF transmitter for car alarm?
 

It works now, I will post the final code here after I re arrange everything.. Here is a prototype code:

Code:
bit infrared,buffer,j,change,writetoeeprom,devam;
unsigned char timepassed=0,eeprombuffer[80];
volatile unsigned char i=0,ii=0,k;
volatile unsigned int timer=0,offtimer=0;
void interrupt()
{
if(INTCON.T0IF)
{
 timer++;
 if(!change && i>5)
            {  offtimer++;
               if(offtimer>1000){ PORTC.F0=~PORTC.F0; writetoeeprom=1; offtimer=0;}
             }
 TMR0=200;
 INTCON.T0IF=0;
}
}
void main(){
   //unsigned char measuretxt[7];
   ANSEL = 0;
   ANSELH = 0;
   PORTC = 0;
   PORTD = 0;
   TRISC = 0;
   TRISD = 0x03;

   OPTION_REG=0x88;
   TMR0=200;
   INTCON.T0IE=1;
   INTCON.GIE=1;
   j=0;
   //LCD_Init();
   buffer=~PORTD.F0;
   writetoeeprom=0;
   devam=1;
   while(devam)
   {
    infrared=~PORTD.F0;
    if(buffer!=infrared)
    {
     if(!j){ timer=0; j=1;}
     else
     {
      timepassed=timer;
      timer=0;
      eeprombuffer[i]=timepassed; //EEPROM_Write(0x00+i,timepassed);
      i++;
     }
     buffer=infrared;
     change=1;
    }
    else
    {
      change=0;
      if(writetoeeprom)
      {
       PORTC.F1=~PORTC.F1;
       writetoeeprom=0;
       for(ii=0;ii<i;ii++)
       {
        EEPROM_Write(0x00+ii,eeprombuffer[ii]);
       }
       devam=0;
      }
    }
    /*
        |-----|    |-----|    |-----|
        |     |    |     |    |     |
    ____|     |____|     |____|     |____

    */
   }
   while(1);
}
 

sahu said:
Fragrance said:
hi

here you go it is based on pic16f84a

regards
Fragrance
can u it share asmably lang. & its fx. also

hi

I do not have any code for this only hex any way user cebrax has share his work thanks to him for his nice job he done, waiting for final version

Regards
Fragrance
 

Re: [SOLVED]Self learning IR transmitter

Hello again!

I finished the receive and store part. But I can't replay. Any help?

Code:
bit infrared,buffer,j,change,writetoeeprom,devam,outputmode;
unsigned char timepassed=0,eeprombuffer[80];
volatile unsigned char i=0,ii=0;
volatile unsigned int timer=0,offtimer=0;

void receive(void);
void transmit(void);

void interrupt()
{
 if(INTCON.T0IF)
 {
  timer++;
  TMR0=200;
  if(PORTD.F2)
  {
   TMR0=0xFF - eeprombuffer[ii++];
   if(ii>=i) {INTCON.T0IE=0; outputmode=0; PORTC.F6=~PORTC.F6; }
   if(outputmode)
   {
    PORTC.F5=~PORTC.F5;
    CCPR1L = 0x08;
    CCP1CON = 0x0C;
   }
   else
   {
    CCPR1L = 0;
    CCP1CON = 0;
   }
   outputmode=~outputmode;
  }
  else if(!change && i>5 && devam)
             {  offtimer++;
                if(offtimer>1000){ writetoeeprom=1; INTCON.T0IE=0;}
              }

 }
 INTCON.T0IF=0;
}
void main(){
    //unsigned char measuretxt[7];
    ANSEL = 0;
    ANSELH = 0;
    PORTA = 0;
    PORTC = 0;
    PORTD = 0;
    TRISC = 0;
    TRISD = 0b00000111;

    OPTION_REG=0x88;
    TMR0=200;
    INTCON.T0IE=1;
    INTCON.GIE=1;
    /*
   * PWM registers configuration
   * Fosc = 20000000 Hz
   * Fpwm = 37878.79 Hz (Requested : 38000 Hz)
   * Duty Cycle = 25 %
   * Resolution is 9 bits
   * Prescaler is 4
   * Ensure that your PWM pin (RC2) is configured as digital output
   * see more details on [url]https://www.micro-examples.com/[/url]
   * this source code is provided 'as is',
   * use it at your own risks
   */
    PR2 = 0b00100000 ;
    T2CON = 0b00000101 ;
    CCPR1L = 0; //0x08 ; // 0b00001000;
    CCP1CON = 0; //0x0C ; // 0b00001100 ;

    j=0;
    //LCD_Init();
    buffer=~PORTD.F0;
    writetoeeprom=0;
    devam=1;
    outputmode=1;
    while(1)
    {
     if(PORTD.F1) receive();
     if(PORTD.F2) transmit();
    }
}
void transmit(void)
{
  if(!j)
  {
    i=EEPROM_Read(0x80);
    for(ii=0;ii<i;ii++)
    {
     eeprombuffer[ii]=EEPROM_Read(0x00+ii);
    }
    j=1;
    ii=0;
    PORTC.F7=~PORTC.F7;
    INTCON.T0IE=1;
    TMR0=0;
  }
}
void receive(void)
{
    while(devam)
    {
     infrared=~PORTD.F0;
     if(buffer!=infrared)
     {
      if(!j){ timer=0; j=1;}
      else
      {
       timepassed=timer;
       timer=0;
       eeprombuffer[i]=timepassed; //EEPROM_Write(0x00+i,timepassed);
       i++;
      }
      buffer=infrared;
      change=1;
     }
     else
     {
       change=0;
       if(writetoeeprom)
       {
        PORTC.F4=~PORTC.F4;
        writetoeeprom=0;
        for(ii=0;ii<i;ii++)
        {
         EEPROM_Write(0x00+ii,eeprombuffer[ii]);
        }
        EEPROM_Write(0x80,i);
        devam=0;
        j=0;
       }
     }
    }
}
 

Re: [SOLVED]Self learning IR transmitter

cebrax said:
Hello again!

I finished the receive and store part. But I can't replay. Any help?

Thanks for sharing what sort help required add a switch when it pressed system goes in learn mode and store noew code in internal eeprom,

regards
Fragrance
 

I already did that I think.. Do you think this is the problem?

Code:
     if(PORTD.F1) receive();
     if(PORTD.F2) transmit();
 

cebrax said:
I already did that I think.. Do you think this is the problem?

Code:
     if(PORTD.F1) receive();
     if(PORTD.F2) transmit();

if you only want to make the receiver then you required self learning switch to add please note that there universal remote transmiter in the market which well work with any system you can used this as test system.

tommorow will try to send you a universal receiver code written basic proton

regards
Fragrance
 

I've completed the learning part, it can successfully store the delays(well, with some 10-20 usec error). Now replaying it is problem.. I don't have an oscilloscope that's why I can't see my output waveform. Can any one out there compile and look at the output?
mikroC PRO for PIC compiler
 

cebrax said:
I've completed the learning part, it can successfully store the delays(well, with some 10-20 usec error). Now replaying it is problem.. I don't have an oscilloscope that's why I can't see my output waveform. Can any one out there compile and look at the output?
mikroC PRO for PIC compiler

If you have proteus you can do it easly in side the proteus (used proteus scope to check signal) let me know which version you have i can guide you how and send you the model for this purpose

regards
Fragrance
 

Thanks Fragrance, I will check it out!
 

Hey all!
After a long delay, I wrote a new program. This one is not working real-time, I mean there is no multi-tasking and stuff... But this works!
I have tested for my TV (VESTEL) and VCR (YUMATU) and they work!
I use TFMS 5360 which is a receiver for 36kHz and I send 36 kHz modulated signals.. Maybe that's why I can't clone my airconditioner's remote...

Here it is! Any suggestion will be really cool

Code:
bit infrared,buffer,change,initial,sample,loop,output;
volatile unsigned int timer=0;
volatile unsigned char i=0,j=0,timetable[70];

void receive(void);
void interrupt()
{
 if(INTCON.T0IF)
 {
  if(timer<65534)timer++;
  TMR0=50;
  //PORTC.F1=~PORTC.F1; // will change per 17.8 usec = 1 timer
  INTCON.T0IF=0;
 }
}
void main()
{
    ANSEL = 0;
    ANSELH = 0;
    PORTA = 0;
    PORTC = 0;
    PORTD = 0;
    TRISC = 0;
    TRISD = 0b00000011;

    OPTION_REG=0x88;
    TMR0=50;
    
    PR2 = 0b00100000 ;
    T2CON = 0b00000101 ;
    CCPR1L = 0x00; // 0x0F ;
    CCP1CON = 0b00001100 ;
  
    INTCON.T0IE=1;
    INTCON.GIE=1;
    initial=1;
    sample=1;
    buffer=~PORTD.F0;
    delay_ms(5000);
    while(1)
    {
      infrared=~PORTD.F0;
      if(buffer!=infrared){change=1;buffer=infrared;PORTC.F1=1;} else change=0;
      if(change && sample)
      {
       if(initial)
       {
        timer=0;
        initial=0;
       }
       else
       {
        timetable[i++]=timer;
        timer=0;
       }
      }
      if(!initial && timer>=2000 && i>2)
      {
       for(j=0;j<=i;j++)
       {
        EEPROM_Write(0x00+j,timetable[j]);
       }
       EEPROM_Write(0x80,i);
       PORTC.F0=1;
       while(1)
       {
        while(PORTD.F1);
        j=0;
        i=EEPROM_Read(0x80);
        for(j=0;j<=i;j++)
        {
         timetable[j]=EEPROM_Read(0x00+j);
        }
        loop=1;
        j=0;
        timer=0;
        CCPR1L = 0x0F;
        for(j=0;j<=i;j++)
        {
         while(timer<timetable[j]);
         timer=0;
         output=~output;//CCPR1L = 0x0F;CCPR1L = 0x00;
         if(output)CCPR1L = 0x0F;
         else CCPR1L = 0x00;
        }
        CCPR1L = 0x00;
        PORTC.F7=~PORTC.F7;
        delay_ms(255);
       }
      }
    }
}
 

This is awesome! being new to microcontrollers, I was trying to figure out a way that I could convert the IR from up/down volume on my dish remote to send the learned IR sequence from my A/V receiver up/down volume which apparently the Dish Network remote doesn't have the codes for. Using your code, I think I'll be able to built a IR receiver/converter/repeater so that I can give my wife the pleasure of one less remote she has to get out.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top