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 CCS Technical Support

SIRC decoding

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



Joined: 13 Jun 2011
Posts: 14
Location: NIGERIA

View user's profile Send private message

SIRC decoding
PostPosted: Sat Apr 21, 2012 4:14 am     Reply with quote

Somebody out there please help. I had been trying to decode Sony TV remote control all to no avail. I have read so much on this on the internet, but the theory seem far different from the practice. I used pic kit2 to analyze the data. It was ok, start 2.52 ms, short bit = 600,640 us. I found a code written in MikroC which I translated to CCS PCW with little modification. But the Timer1 readings are not as expected. What am I doing wrong ? Someone please help. Here is the code:
Code:

#include <16F887.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=16000000)
#include <Flex_LCD.c>

#BYTE PIR1 = 0x0c
//#BIT INTF = 1
unsigned input_data, bit_count,i;
int16 CAPT = 0,CAPT1 = 0,CAPT2=0;

enum {
        Idle,
        Start_bit,
        Capture_bit
};

char Current_state = Idle;
char got_data = 0;
char Command_code, Device_code;

#int_ext // Interrupt name
void interrupt(){
     if(interrupt_active(int_ext)){
        switch (Current_state){
           case Idle:
                 set_timer1(0);
                 ext_int_edge(L_TO_H);            //interrupt on rising edge.
                      Current_state = Start_bit;
                      break;
           //found the rising edge, check lenght for 2.4ms
           case Start_bit:
                    CAPT = get_timer1();
                    set_timer1(0);
                      //correct signal, move on to next state
                      if((CAPT>=2000)&&(CAPT>=2800)) {
                      //output_high(PIN_B1);// this pin will only go high when     //CAPT is b/w 44520 and 44590, dont know why
                         bit_count = 0;
                         input_data = 0;
                         Current_state = Capture_bit;
                         } else {
                            //fault signal, reset to Idle
                            Current_state = Idle;
                         }
                      break;
           case Capture_bit:
                      //check plus length for 0 or 1, 0 = 1.2ms and 1 = 1.8ms
                      CAPT1 = get_timer1();
                    set_timer1(0);
                      if((CAPT>=900)&&(CAPT<=1500)){
                      //output_high(PIN_B2);// this pin will only go high when //CAPT is b/w 44520 and 44590, dont know why
                         input_data >>= 1;         // add 0 to received data
                         bit_count++;
                      }else {
                       if((CAPT>=1500)&&(CAPT<=2100)){
                       //output_high(PIN_B3);// this pin will only go high when //CAPT is b/w 44520 and 44590, dont know why
                            input_data >>= 1;
                            input_data |= 0x8000;     //add 1 to received data
                            bit_count++;
                      } else {
                            //error occurs, reset to Idle state
                            ext_int_edge(H_TO_L);    //interrupt on falling edge.
                            Current_state = Idle;
                         }
                       }
                      //compleat 12 bit
                      if(bit_count >= 12){
                         got_data = 1;
                         input_data >>= 4;
                         ext_int_edge(H_TO_L);      //interrupt on falling edge.
                         Current_state = Idle;
                      }
                      break;
            default: Current_state = Idle;
        }
      clear_interrupt(int_ext);       //clear interrupt flag.
     }
        enable_interrupts(int_ext);
        enable_interrupts(global);
}

 //********************************************
void main(){
//set_tris_b(0x01);
enable_interrupts(int_ext); // Enable named interrupt
clear_interrupt(int_ext);
ext_int_edge(H_TO_L); // Interrupt signal polarit
enable_interrupts(global); // Enable all interrupts
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
   set_timer1(0);
      lcd_init();
    printf(lcd_putc"\f");
    // lcd_gotoxy(11,1);
     lcd_putc ("IR DECODING");
    lcd_gotoxy(1,2);
    lcd_putc ("Command:");

//**********************************************************//// Introduced this section of the code to test timer1 and crystal
// if they are functioning properly using PIC KIT2 the result was OK
//***********************************************************    for(i=0;i<4;i++){
    set_timer1(63136);  // Timer1 interrupt flag will set in 2.4 ms.
    output_low(PIN_B4); // this pin was connected to PIC KIT2 for the test
                        //result of test gave 2.38 ms @ 40 ms window
    while(!(PIR1&(1<<0))){}// wait until interrupt flag is set
    output_high(PIN_B4);
    clear_interrupt(int_timer1);
    delay_ms(1);// test result gave 1.04 ms, @40ms window
    }
//***********************************************************//***********************************************************

while(1)
{
//***********************************************************//I included this section to show the detected times which happens to differ from my expectations
  lcd_gotoxy(12,2);
   printf(lcd_putc,"%lu",CAPT);
   delay_ms(2000);
   lcd_gotoxy(12,2);
   printf(lcd_putc,"%lu",CAPT1);
   delay_ms(2000);
   lcd_gotoxy(12,2);
   printf(lcd_putc,"%lu",CAPT2);
   delay_ms(2000);
//***********************************************************          if(got_data){
           printf(lcd_putc"\f");// clear LCD
           // lcd_gotoxy(11,1);
           lcd_putc ("IR DECODING");//print "IR DECODING"
           lcd_gotoxy(1,2);
           lcd_putc ("Command:");// print "Command:"
            Command_code = input_data & 0x7F;//extract command code from input_data
            Device_code = input_data >> 7;//get Device code from input data
            got_data = 0;
            if(Device_code == 1){
               switch (Command_code){
                  case 0:
                 lcd_gotoxy(12,2);
                 printf(lcd_putc,"%U",Command_code); break;
                  case 1:
                  lcd_gotoxy(12,2);
                  printf(lcd_putc,"%U",Command_code); break;
                  case 2:
                  lcd_gotoxy(12,2);
                 printf(lcd_putc,"%U",Command_code); break;
                  case 3:
                  lcd_gotoxy(12,2);
                 printf(lcd_putc,"%U",Command_code); break;
                  case 4:
                  lcd_gotoxy(12,2);
                 printf(lcd_putc,"%U",Command_code); break;
                  case 5:
                  lcd_gotoxy(12,2);
                 printf(lcd_putc,"%U",Command_code); break;
                  case 6:
                  lcd_gotoxy(12,2);
                 printf(lcd_putc,"%U",Command_code); break;

 }
 
   }
          }
}
}
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Sat Apr 21, 2012 12:14 pm     Reply with quote

I haven't played with SIRC, and have no current plans for it. But DHouston from the following links usually has good information on the topic: http://www.sbprojects.com/knowledge/ir/index.php
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 21, 2012 3:13 pm     Reply with quote

Learn to use the forum's search page. It's here:
http://www.ccsinfo.com/forum/search.php
Search for this:
Quote:

Sony remote

And set the search to: Search for all terms

Examples of threads on Sony remote control:
http://www.ccsinfo.com/forum/viewtopic.php?t=26226
http://www.ccsinfo.com/forum/viewtopic.php?t=44113
http://www.ccsinfo.com/forum/viewtopic.php?t=38192
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