infrared sony remote - 16f877a help

Status
Not open for further replies.

deperkin

Member level 2
Joined
Apr 12, 2009
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,776
Hello all!
I am attempting to program a 16f877a for infrared.
I am using a Vishay tsop1138 for recieving.
and I am programing it with CCS.

the code below is not my own, but can be found at:
https://www.ccsinfo.com/forum/viewtopic.php?t=26226

I have replaced main() with:
void main () {
while(1){
output_high(pin_b1);
}
}

and have placed an LED on B1, but get nothing.

could this code below have some resetting problem?

also, does the MIN/MAX's seem to be calculated correctly ? (please see original post on CCS)

Code:

#include <16F877A.h>
#include <def_877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)



/* TIMER0 configuration */
#define TIMER1_CONFIG T1_INTERNAL | T1_DIV_BY_1

/* Interrupt rate: */
/* 4/20000000*65536*1 = 13.1 ms */
/* */
/* Start: 3.0 ms (ignored) */
/* "1": 1.8 ms (9000) */
/* "0": 1.2 ms (6000) */

#define ONE_MIN 8000
#define ONE_MAX 10000
#define ZERO_MIN 5000
#define ZERO_MAX 7000

//#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() {output_bit(PIN_A5, 0);
if (irdone) return;
irframes[ircount++] = get_timer0();
if (ircount >= 13)
irdone = TRUE;
set_timer0(0);
enable_interrupts(INT_TIMER1);
}


#int_timer1
void timer_isr() {
disable_interrupts(INT_TIMER1);
}


#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) && (irframes <= ONE_MAX))
bits = 0x01;
else
if ((ZERO_MIN <= irframes) && (irframes <= ZERO_MAX))
bits = 0x00;
else // Error
return FALSE;
}

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

mask = 0x01;
for (i=8; i<=12; i++) {
if (bits)
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(0x00);
set_tris_b(0b11111111);
set_tris_c(0b11111011); // PIN_C2 used for the LED
set_tris_d(0b00000000); // LCD
set_tris_e(0b11111111);
setup_spi(FALSE);

output_bit(PIN_A5, 1);
//lcd_init();
//output_bit(PIN_C2, 0);
delay_ms(100);

//lcd_putc("\fWaiting...");


setup_timer_1(TIMER1_CONFIG);
setup_timer_2(T2_DISABLED, 255, 1);
ext_int_edge(0, L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
delay_ms(100);
start_ir();
while(TRUE) {

if (irdone) {
ok = decode_ir(addr, cmd);
printf("%u", cmd);
printf("%u", addr);
if (!ok){
printf("1111");}
else
output_bit(PIN_A5, 0);
delay_ms(50);
output_bit(PIN_A5, 1);
start_ir();
}
}
}

Added after 5 hours 16 minutes:


no one??
I have even tried the code below, and still cant get a hello world on a0...


#include <16F877A.h>
#include <def_877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define TIMER1_CONFIG T1_INTERNAL | T1_DIV_BY_1



void main() {

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
set_tris_a(0x00);
set_tris_b(0b00000000);
set_tris_c(0b11111011); // PIN_C2 used for the LED
set_tris_d(0b00000000); // LCD
set_tris_e(0b11111111);
setup_spi(FALSE);

while(TRUE) {
output_high(pin_a0);
delay_ms(100);
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…