electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Self learning IR transmitter


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Self learning IR transmitter
Author Message
cebrax



Joined: 24 Apr 2009
Posts: 11


Post24 Oct 2009 1:07   

Self learning IR transmitter


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++;
     }
    }
}


Last edited by cebrax on 29 Oct 2009 14:49; edited 2 times in total
Back to top
hanif



Joined: 14 Feb 2007
Posts: 73
Helped: 7
Location: Pakistan


Post24 Oct 2009 5:23   

Re: Self learning IR transmitter


view these topics

Self learning IR remote control transmitter

http://www.freepatentsonline.com/5691710.html

Serial port controlled infrared transmitter based on PIC

http://jap.hu/electronic/irtx_pic.html
Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post24 Oct 2009 11:40   

Self learning IR transmitter


anyone has a c code example?
Back to top
Fragrance



Joined: 26 Jul 2002
Posts: 1385
Helped: 24


Post26 Oct 2009 5:07   

Re: Self learning IR transmitter


hi

here you go it is based on pic16f84a

regards
Fragrance



Sorry, but you need login in to view this attachment

Back to top
sajal1975



Joined: 25 Mar 2005
Posts: 150
Helped: 3


Post26 Oct 2009 11:16   

Re: Self learning IR transmitter


RADIO TRANSMITTER WANT SOME HLP
Back to top
linoko



Joined: 25 Jun 2004
Posts: 43
Helped: 2


Post26 Oct 2009 15:58   

Re: Self learning IR transmitter


Hi all,
What about self learning RF transmitter for car alarm?
Back to top
sahu



Joined: 09 Oct 2009
Posts: 43
Helped: 3
Location: india


Post26 Oct 2009 18:44   

Re: Self learning IR transmitter


Fragrance wrote:
hi

here you go it is based on pic16f84a

regards
Fragrance

can u it share asmably lang. & its fx. also
Back to top
Google
AdSense
Google Adsense




Post26 Oct 2009 18:44   

Ads




Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post28 Oct 2009 21:17   

Re: Self learning IR transmitter


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);
}
Back to top
Fragrance



Joined: 26 Jul 2002
Posts: 1385
Helped: 24


Post29 Oct 2009 6:24   

Re: Self learning IR transmitter


sahu wrote:
Fragrance wrote:
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
Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post29 Oct 2009 14:38   

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 http://www.micro-examples.com/
   * 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;
       }
     }
    }
}
Back to top
Fragrance



Joined: 26 Jul 2002
Posts: 1385
Helped: 24


Post30 Oct 2009 4:26   

Re: [SOLVED]Self learning IR transmitter


cebrax wrote:
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
Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post30 Oct 2009 10:48   

Re: Self learning IR transmitter


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

Code:

     if(PORTD.F1) receive();
     if(PORTD.F2) transmit();
Back to top
Fragrance



Joined: 26 Jul 2002
Posts: 1385
Helped: 24


Post30 Oct 2009 12:14   

Re: Self learning IR transmitter


cebrax wrote:
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
Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post30 Oct 2009 16:45   

Self learning IR transmitter


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
Back to top
Fragrance



Joined: 26 Jul 2002
Posts: 1385
Helped: 24


Post31 Oct 2009 4:23   

Re: Self learning IR transmitter


cebrax wrote:
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
Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post31 Oct 2009 9:48   

Self learning IR transmitter


Proteus 7.4 SP3
Back to top
Fragrance



Joined: 26 Jul 2002
Posts: 1385
Helped: 24


Post04 Nov 2009 8:15   

Re: Self learning IR transmitter


cebrax wrote:
Proteus 7.4 SP3


you may go here model i already pm you

http://www.sonelec-musique.com/logiciels_proteus_easyhdl_rc5_en.html

regards
Fragrance
Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post04 Nov 2009 23:51   

Self learning IR transmitter


Thanks Fragrance, I will check it out!
Back to top
cebrax



Joined: 24 Apr 2009
Posts: 11


Post09 Nov 2009 1:42   

Re: Self learning IR transmitter


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);
       }
      }
    }
}

Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Self learning IR transmitter
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Self-check Testbench Learning (3)
self learning remote control car (3)
QPSK-OFDM Transmitter and QPSK transmitter (14)
learning to Interface !!!! (3)
specman learning (28)
learning electronics. (3)
learning asm (3)
learning electronics (31)
Learning HSpice (6)
Learning Simulink (5)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS