CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem in decoding remote signal

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

problem in decoding remote signal
PostPosted: Tue Aug 21, 2007 9:49 am     Reply with quote

i try below program to decode the TV remote signal, but i dont have any output from the PIC. i connect the IR out to the B0 pin of PIC

Code:
#include<16F873a.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT

#use rs232(baud=19200,parity=N,xmit=PIN_a0,rcv=PIN_a1,bits=8,enable=PIN_C5)
INT8  Counter=0;
INT16 time[25];
INT1  Received=0;
INT1  fejl;
INT8  Code[17];

#int_EXT

EXT_isr()
{
 time[counter]=get_timer0();
 set_timer0(0);
 Counter++;
 IF (counter==22)Received=TRUE;
}

#int_TIMER0
TIMER0_isr()
{
counter=0;
}

void Check_Start_Stop()
{
fejl =0;
IF (time[1]<5250 || time[1]>10500) {fejl=1;Break;}
IF (time[2]<5250 || time[2]>10500) {fejl=1;Break;}
IF (time[3]<33500 || time[3]>42000) {fejl=1;Break;}
IF (time[4]<5250 || time[4]>10500) {fejl=1;Break;}
IF (time[21]<26000 || time[21]>33500) {fejl=1;Break;}
}
void Check_Code()
{
INT8 i;
For (i=0;i<=15;i++)
 {
  IF (time[i+5]<5250) fejl=1;
  IF (time[i+5]>5250) code[i]='A';
  IF (time[i+5]>10500) code[i]='B';
  IF (time[i+5]>18250) code[i]='C';
  IF (time[i+5]>26000) fejl=1;

 }
}
void read_remote()
{
Check_start_stop();
IF (!fejl)
 check_code();
 IF (!fejl)
 {
 code[16]=0x00;
 Output_High(PIN_C5);
 Delay_us(500);
 printf(code);
 printf("\r");
 }
received=0;
}

void main()
{
 setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   //setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   //setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER0);
   DO
   {
   IF (received) read_remote();
   }
   WHILE (true);
}



please give the solution for this program...
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Tue Aug 21, 2007 11:01 am     Reply with quote

Timer 0 on the 16F873A is an 8-bit timer. Try using Timer 1. I don't know the specific sony remote but your algorithm looks reasonable, I see you are skipping time[0] correctly as that is where you first init the timer.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Aug 21, 2007 12:32 pm     Reply with quote

Code:
 printf(code);
I'm not sure if this will print your string. Try changing into
Code:
 printf("%s \r\n", code);
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Aug 21, 2007 5:16 pm     Reply with quote

I would like to give you some comments:

1) Trying to decode an IR signal without some tools for debugging it is not a trivial task
for a beginner.

2) Try to be sure that the RS232 communication is working properly.
This will enable you to monitor some events and print out the contents of the related variables.

3) Try to write some code that really help you in the debugging stage. It is useless to
write "definitive code" while you still doesn´t know if something is working or not.

4) Try to wire some LED´s in the unused pins to use them as visible flags.

5) Inside the interrupt handler, you use the following code:
Code:
     IF (counter==22) Received=TRUE;

while you still doesn´t know if the interrupt was fired or not.

6) Instead, you could use a more relaxed test.
Code:
     if (counter>n) Received=TRUE;

Just to be sure that EXT_INT had been triggered n times, it will be enough in debugging stage.
Once this work as expected, write code to make a fine tune according to your algorithm.

7) It is better to use a visible flag like:
output_high(PIN_xx); and connect a LED in that pin.

8) In the main loop, add a long delay (>2000 ms) and use the printf capabilities
to know the desired variables and/or status flags.

9) Do not forget to shut down the LEDs inside main()

10) I must admit -according to your code in the main()- that you are a very optimistic man !!!
Shocked (I hope you accept this joke)

Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group