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
#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
?