|
|
View previous topic :: View next topic |
Author |
Message |
Andrew83
Joined: 16 Sep 2008 Posts: 51
|
|
Posted: Tue Feb 10, 2009 8:28 am |
|
|
Here is today's code :
Code: |
#include <18f452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define tsop pin_b0
char buffer[10];
char bitnumber;
int1 val_complete;
#int_ext //IR bits detected by edge triggering
void ext_isr() {
clear_interrupt(INT_TIMER1); //clear interrupt flag
enable_interrupts(INT_TIMER1); // enable intrerupere timer1
set_timer1(62786); // overflow in 1,1 ms
disable_interrupts(int_ext); //adio intrerupere la edge
bitnumber=10;
}
#int_timer1
void timer1_isr() {
set_timer1(61061); // overflow in 1,790 ms
if (input(TSOP))
buffer[bitnumber]='1';
else
buffer[bitnumber]='0';
if (--bitnumber==0) {
disable_interrupts(INT_TIMER1); //adio intrerupere timer1
clear_interrupt(INT_EXT); //clear interrupt flag
enable_interrupts(int_ext); //enable intrerupere la edge
val_complete=true;
}
}
void main() {
setup_timer_1(t1_internal|t1_div_by_1);
ext_int_edge(0,H_to_L); //falling edge
enable_interrupts(int_ext); //enable external interrupt
enable_interrupts(global); //enable interrupts
while(1) {
if (val_complete)
{
val_complete=false;
printf("%s",buffer);
}
}
}
|
|
|
|
Andrew83
Joined: 16 Sep 2008 Posts: 51
|
|
Posted: Tue Feb 10, 2009 8:35 am |
|
|
The output for printf("%s",buffer); is :
Code: |
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPP
|
And for printf("%c",buffer); is :
Code: |
BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0
BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB0BB
0BB0BB0BB0BB0BB0BB0BB0BB0BB0
|
|
|
|
Andrew83
Joined: 16 Sep 2008 Posts: 51
|
|
Posted: Tue Feb 10, 2009 8:37 am |
|
|
Here is the transmitter code :
Code: |
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
char slave_cmd[10]={'1','1','1','0','1','0','1','0','1','0'};
//char slave_cmd[10]={'1','0','1','0'}; //debug
//=============================================================================
void check_for_SLAVE(void) {
char i;
output_high(pin_e1);
delay_ms(2);
for(i=0;i<9;i++)
{
if (slave_cmd[i]=='0')
{
output_high(pin_e1);
delay_us(900);
output_low(pin_e1);
delay_us(900);
}
else
{
output_low(pin_e1);
delay_us(900);
output_high(pin_e1);
delay_us(900);
}
}
output_high(pin_e1);
delay_ms(100);
}
//==========================================
void main() {
//--------------------------------------------------
setup_timer_1(t1_internal|t1_div_by_1);
ext_int_edge(0,h_to_l);
enable_interrupts(int_ext);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(1)
{
check_for_SLAVE();
}
}
|
|
|
|
Andrew83
Joined: 16 Sep 2008 Posts: 51
|
|
Posted: Tue Feb 10, 2009 9:52 am |
|
|
Ok...so i've modified the timer1 ISR by including the second IF statement in the ELSE of the first, and i get over the serial "10 80 41 02" in hex over and over again..but this time, only when i transmit iR data.
Still no luck in decoding the data transmitted.
Code: |
#int_timer1
void timer1_isr() {
set_timer1(61061); // overflow in 1,790 ms
if (input(TSOP))
buffer[bitnumber]='1';
else
{
buffer[bitnumber]='0';
if (--bitnumber==0) {
disable_interrupts(INT_TIMER1); //adio intrerupere timer1
clear_interrupt(INT_EXT); //clear interrupt flag
enable_interrupts(int_ext); //enable intrerupere la edge
val_complete=true; }
}
}
|
|
|
|
Ttelmah Guest
|
|
Posted: Wed Feb 11, 2009 3:31 am |
|
|
Unfortunately, _you_ need to start thinking...
Now (for example), you are blithely trying to print outputs, without checking if what you are sending is useable with the output format instructions.
Is 'buffer' a character (which is what %c expects). No. It is the address of a character.
Is 'buffer' a string (which is what %s expects). No. Strings in C, require termination. Where is the space for this?. Are you terminating it?.....
People here will _help_ you, but not write eveerything for you. Your code has basic faults, which are nothing to do with reading the IR stream.
Best Wishes |
|
|
|
|
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
|