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

problem with sony remote code...

 
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 with sony remote code...
PostPosted: Thu May 29, 2008 8:41 am     Reply with quote

hai friends,


i try sony decoder program from code library , i modified as my PIC and crystal.

program is decode the signal and give the data in RS232 port, but received data is not correct data. please check the program and give correct solution..


Code:
#include <16F873A.H>

#use delay(clock=4000000)
//#include <lcd.c>
#fuses xt,nowdt,noprotect,noput,nolvp
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8)

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

#ignore_warnings none

#zero_ram

/* TIMER0 configuration */
#define TIMER0_CONFIG   RTCC_INTERNAL | RTCC_DIV_1

/* Interrupt rate:                     */
/* 4/32000000*65536*1 = 8.192 ms       */
/*                                     */
/*     Start: 3.0 ms (ignored)         */
/*     "1":   1.8 ms (14400)           */
/*     "0":   1.2 ms  (9600)           */

#define ONE_MIN  13400
#define ONE_MAX  15400
#define ZERO_MIN 8600
#define ZERO_MAX 10600

//#include "lcd.c"


/* irframes[0] (start) will be garbage, ignore it...  */
int16 irframes[13];
int8 ircount = 0;
int1 irdone = FALSE;


#int_ext
void ext_isr() {
  if (irdone) return;
  irframes[ircount++] = get_timer0();
  if (ircount >= 13)
    irdone = TRUE;
  set_timer0(0);
  enable_interrupts(INT_TIMER0);
}


#int_timer0
void timer0_isr() {
  disable_interrupts(INT_TIMER0);
}


#separate
int1 decode_ir(int8 &addr, int8 &cmd) {
  int8 i;
  int8 mask;
  int8 bits[13];

  addr = 0;
  cmd = 0;

  for (i=1; i<=12; i++) {
    if ((ONE_MIN <= irframes[i]) && (irframes[i] <= ONE_MAX))
      bits[i] = 0x01;
    else
      if ((ZERO_MIN <= irframes[i]) && (irframes[i] <= ZERO_MAX))
        bits[i] = 0x00;
      else        // Error
        return FALSE;
  }

  mask = 0x01;
  for (i=1; i<=7; i++) {
    if (bits[i])
      cmd = cmd | mask;
    mask <<= 1;
  }

  mask = 0x01;
  for (i=8; i<=12; i++) {
    if (bits[i])
      addr = addr | mask;
    mask <<= 1;
  }

  return TRUE;
}


void start_ir() {
  memset(irframes, 0x00, sizeof(irframes));
  ircount = 0;
  irdone = FALSE;
}


void main() {
  int8 addr, cmd;
  int1 ok;

  delay_ms(100);
  setup_adc_ports(NO_ANALOGS);
  setup_adc(ADC_OFF);
  set_tris_a(0b11111111);
  set_tris_b(0b11111111);
  set_tris_c(0b11111011);  // PIN_C2 used for the LED

  setup_spi(FALSE);
  //setup_wdt(WDT_OFF);


  output_bit(PIN_C2, 0);
  delay_ms(100);

 printf("\fWaiting...");

  setup_timer_0(TIMER0_CONFIG);
  ext_int_edge(0, L_TO_H);
  enable_interrupts(INT_EXT);
  enable_interrupts(GLOBAL);

  start_ir();
#ignore_warnings 203
  while(TRUE) {
#ignore_warnings NONE
    if (irdone) {
      ok = decode_ir(addr, cmd);
      printf("\fCmd  %3u\nAddr %3u", cmd, addr);
      if (!ok)
         printf("  ERROR");
      else
        output_bit(PIN_C2, 1);
      delay_ms(50);
      output_bit(PIN_C2, 0);
      start_ir();
    }
  }
}
ckielstra



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

View user's profile Send private message

PostPosted: Thu May 29, 2008 9:05 am     Reply with quote

Yesterday you did a post for RC5 and now for the Sony protocol, you are just fiddling around?

- When you copy code from somebody else then it is polite to keep the original author's name in the code.
- You make it a lot easier for us to find an error when you post the link to the original code so we can compare the differences. The original code can be found here.
- What behaviour do you see and what is expected?
- What does your hardware look like and how is it connected?


Hint:
Code:
/* Interrupt rate:                     */
/* 4/32000000*65536*1 = 8.192 ms       */
/*                                     */
/*     Start: 3.0 ms (ignored)         */
/*     "1":   1.8 ms (14400)           */
/*     "0":   1.2 ms  (9600)           */

#define ONE_MIN  13400
#define ONE_MAX  15400
#define ZERO_MIN 8600
#define ZERO_MAX 10600
When you reduced the clock rate from 32MHz to 4MHz you should have adapted these timings too.
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