Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 28, 2024, 08:04:57 08:04


Login with username, password and session length


Pages: [1]
Print
Author Topic: Grab IR Code (CCS C)  (Read 6257 times)
0 Members and 1 Guest are viewing this topic.
Kova
Junior Member
**
Offline Offline

Posts: 68

Thank You
-Given: 172
-Receive: 24



« on: August 26, 2009, 03:34:28 15:34 »

Hi all,
I want to grab a single IR Code (only 1 button) from a generic remote controller.
So I thinked to compare the time between the received IR code and the memorized IR code.

I hope that this code is a bit clear Cheesy
Code:
#include <18F4550.h>
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, MCLR, NOLVP, NOCPD
#define LCD_ENABLE_PIN  PIN_E1 //E0                            
#define LCD_RS_PIN      PIN_E0 //E1                              
#define LCD_RW_PIN      PIN_E2                                  
#define LCD_DATA4       PIN_D4                                  
#define LCD_DATA5       PIN_D5                                  
#define LCD_DATA6       PIN_D6                                  
#define LCD_DATA7       PIN_D7
#include "lcd.c"

INT8  Counter=0;
INT16 time[32];
INT16 time2[32];
INT1  Received=0;
INT1  AltoBasso=0;
INT1  Falso=0;
INT1  Cicalino=0;


#int_EXT
void EXT_isr(void)
{
//It is necessary because when pic startup there is an interrupt
if (Falso==0)
{
set_timer1(0);
Falso=1;
return;
}

 time[counter]=get_timer1();
 set_timer1(0);
 counter++;
 
//Switch from High and Low
if (AltoBasso==0)
   {
      ext_int_edge(0,L_TO_H);
      AltoBasso=1;
   }
   else if (AltoBasso==1)
   {
      ext_int_edge(0,H_TO_L);
      AltoBasso=0;
   }

//Grab max 32 edge
  if (counter==32)
  {
   Received=1;
   disable_interrupts(INT_EXT);
  }
}

#int_TIMER1
void TIMER1_isr(void)
{
counter=0;
}

void AzzeraCode(void)
{
int i=0;
   for(i=0;i<32;i=i+1)
   {
   time[i]=0;
   }
}

void write_long_to_eeprom(int8 addr, int16 data)
{
 int8 i2;

 for(i2 = 0; i2 < 2; i2++)
     write_eeprom(addr + i2, *((int8*)&data + i2) ) ;
}

int16 read_long_from_eeprom(int8 addr)
{
int8 i2;
int16 data;

for(i2 = 0; i2 < 2; i2++)
   *((int8*)&data + i2) = read_eeprom(addr + i2);

return(data);
}

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   ext_int_edge(0,H_TO_L);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
  
   lcd_init(); //Initialise LCD
   delay_ms(250);
  
   lcd_putc("\fHello\n");
  
   while(1)
   {
    int ct=0;
    int contatore=0;
  
    if(Received==1)
      {        
         counter = 0;
         Received = 0;

     if(cicalino==0)
     {
       for(ct=0;ct<32;ct=ct+1)
         {
            write_long_to_eeprom(ct*2, time[ct]);
            lcd_putc("Write\n");
         }
              for(ct=0;ct<32;ct=ct+1)
            {
               time2[ct] = read_long_from_eeprom(ct*2);
               lcd_putc("\fRead\n");
            }
      cicalino=1;
     }
    
     else if (cicalino==1)
     {
         for(ct=1;ct<32;ct=ct+1)
         {  
          if ( abs((time[ct]-time2[ct])) < 300) //Threshold
            {
              contatore = contatore +1;
            }
         }
        
         if (contatore >28) //Good?
            {
            lcd_putc("\fCorrect\n");
            }
         else
            {
            lcd_putc("\fNot Correct\n");
            }
         contatore = 0;
        }
      
       AzzeraCode();
       enable_interrupts(INT_EXT);
      }

   }
}

I capture the signal from an IR Decoder (TMFS5000).
In the absence of IR light, the output of the decoder is normally high.

The problem is that when I grab the code (a same code) the time of each edge is always different, very different!!!

Some help Wink?
Logged
jaikumar
Junior Member
**
Offline Offline

Posts: 46

Thank You
-Given: 49
-Receive: 18


« Reply #1 on: August 27, 2009, 06:30:52 06:30 »

Try asking the question on the forum below:

http://www.ccsinfo.com/forum/


Regards,
Jai
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC