muratti Guest
|
RS232 problem |
Posted: Mon Jul 24, 2006 8:56 am |
|
|
HI;
I am very new at pic. 2 pic16F877 boards are interfaced to each other via B2 and B3 ports. One of the board is connected to pc by C6 and C7 and the DB9 connector of second board is shorted. And I wrote a simple code which take the char by C7 and send it to 2nd pic by B2 and 2nd pic get it by B3 and send it to DB9 by C7 and since DB9 shorted get it back with C7 and send it to another board by B2. and then the first board sends it back to pc via C6. (...max232 is used to connect pc...)
Boards are working when initally started however if i disconnect the DB9 connector of the 2nd board and write a char to pc, it is not echoed back to pc as expected. In the case of shorting DB9 It should work again but it does not. Any idea to sort it out?
I am sure that there is smt wrong with code which I dont know.
In case I added the codes of the pics:
Code of 1st PIC;
#include <16F877>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#USE RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
void put_to_a( char c ) {
putc(c);
}
char get_from_a() {
return getc(); }
#USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3)
void put_to_b( char b ) {
putc(b);
}
char get_from_b() {
return getc(); }
main() {
char c;
while(TRUE) {
put_to_b(get_from_a());
put_to_a(get_from_b());
}
Code of 2nd Pic:
#include <16F877>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#USE RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
void put_to_a( char c ) {
putc(c);
}
char get_from_a() {
return getc(); }
#USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3)
void put_to_b( char b ) {
putc(b);
}
char get_from_b() {
return getc(); }
main() {
char c;
while(TRUE) {
put_to_b(get_from_a());
put_to_a(get_from_b());
} |
|