Advertisement
abdullahkahraman

IR Cloner

Apr 2nd, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. bit infrared,buffer,change,initial,sample,loop,output;
  2. volatile unsigned int timer=0;
  3. volatile unsigned char i=0,j=0,timetable[70];
  4.  
  5. void receive(void);
  6. void interrupt()
  7. {
  8.  if(INTCON.T0IF)
  9.  {
  10.   if(timer<65534)timer++;
  11.   TMR0=50;
  12.   //PORTC.F1=~PORTC.F1; // will change per 17.8 usec = 1 timer
  13.   INTCON.T0IF=0;
  14.  }
  15. }
  16. void main()
  17. {
  18.     ANSEL = 0;
  19.     ANSELH = 0;
  20.     PORTA = 0;
  21.     PORTC = 0;
  22.     PORTD = 0;
  23.     TRISC = 0;
  24.     TRISD = 0b00000011;
  25.  
  26.     OPTION_REG=0x88;
  27.     TMR0=50;
  28.    
  29.     PR2 = 0b00100000 ;
  30.     T2CON = 0b00000101 ;
  31.     CCPR1L = 0x00; // 0x0F ;
  32.     CCP1CON = 0b00001100 ;
  33.  
  34.     INTCON.T0IE=1;
  35.     INTCON.GIE=1;
  36.     initial=1;
  37.     sample=1;
  38.     buffer=~PORTD.F0;
  39.     delay_ms(5000);
  40.     while(1)
  41.     {
  42.       infrared=~PORTD.F0;
  43.       if(buffer!=infrared){change=1;buffer=infrared;PORTC.F1=1;} else change=0;
  44.       if(change && sample)
  45.       {
  46.        if(initial)
  47.        {
  48.         timer=0;
  49.         initial=0;
  50.        }
  51.        else
  52.        {
  53.         timetable[i++]=timer;
  54.         timer=0;
  55.        }
  56.       }
  57.       if(!initial && timer>=2000 && i>2)
  58.       {
  59.        for(j=0;j<=i;j++)
  60.        {
  61.         EEPROM_Write(0x00+j,timetable[j]);
  62.        }
  63.        EEPROM_Write(0x80,i);
  64.        PORTC.F0=1;
  65.        while(1)
  66.        {
  67.         while(PORTD.F1);
  68.         j=0;
  69.         i=EEPROM_Read(0x80);
  70.         for(j=0;j<=i;j++)
  71.         {
  72.          timetable[j]=EEPROM_Read(0x00+j);
  73.         }
  74.         loop=1;
  75.         j=0;
  76.         timer=0;
  77.         CCPR1L = 0x0F;
  78.         for(j=0;j<=i;j++)
  79.         {
  80.          while(timer<timetable[j]);
  81.          timer=0;
  82.          output=~output;//CCPR1L = 0x0F;CCPR1L = 0x00;
  83.          if(output)CCPR1L = 0x0F;
  84.          else CCPR1L = 0x00;
  85.         }
  86.         CCPR1L = 0x00;
  87.         PORTC.F7=~PORTC.F7;
  88.         delay_ms(255);
  89.        }
  90.       }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement