karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
problem with sony remote code... |
Posted: Thu May 29, 2008 8:41 am |
|
|
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();
}
}
}
|
|
|