hi friends
below i'm providing my code for rc5 decoding but when i tested it everytime led connected to pc1 glows.i also check tsop ,it gives voltage of 4.86v when there is no ir signal from philips ir remote and when i pressed any button from remote its voltage drops to 4.26v and only PC1 led glows. i don't know where i'm going wrong? please help me
in my coding i'm waiting for first low voltage then i'm providing delay of 4.752ms so that code flow jumps to half of first half of first address bit and then i'm providing delay of 1.728ms to read next 11 bits
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
#define IR PB0
void init_timer0(void);
unsigned int decode_rc5(void);
volatile uint8_t timer_flag=0;
unsigned int temp=0;
unsigned int rc5_data=0;
unsigned int command=0;
unsigned char result=0;
//defining macros
#define TIMER_STOP 0
#define WAIT_FOR_TIMER() {while(timer_flag==0); timer_flag=0;}
void init_timer0(void)
{
cli();
TCCR0|=(1<<WGM01)|(1<<CS02)|(1<<CS00);// prescaler clk/1024 ,ctc mode,oc0 disconnect
TIMSK|=(1<<OCIE0); // compare match interrupt enable
OCR0=74; // generating delay of 4.752ms
TCNT0=0;
sei();
}
ISR(TIMER0_COMP_vect)
{
timer_flag=1; // setting flag
OCR0=27; // modifying compare value for the delay of 1.728ms
}
unsigned int decode_rc5(void)
{
init_timer0();
WAIT_FOR_TIMER(); // waiting for the delay of 4.752 ms
for(int x=0;x<11;x++)
{
if(PINB&(1<<IR))
{
temp=temp|0X01;
}
rc5_data=temp<<1;
WAIT_FOR_TIMER();
}
TCCR0=TIMER_STOP; // timer0 stop
command=(rc5_data&0X003F); // extracting command
return command;
}
int main(void)
{
DDRB&=~(1<<IR); // declaring IR pin as i/p
PORTB|=(1<<IR); // making IR pin high
DDRC=0XFF; // portc as o/p port
while(1)
{
while(PINB&(1<<IR)) // waiting for ir signal
{
}
result=decode_rc5(); // decoding ir data
PORTC=result; // applying command to PORTC
_delay_us(1);
}
return 0;
}