View Single Post
Old 10-08-2008, 03:32 AM   #13
Khách
Guest
 
Bài gửi: n/a
Androisa

Trích:
Nguyên văn bởi toufik View Post
Hell All,
I want to control two equipement with pic 16f877, so 2 ports, and the intructions are sent from my PC, so anouther port.
Does anybody know how to do that?
Thanks in advance for any help you might provid.
Hi from Mexico!! navigating the web i found your Q. and i hope that this small code still be useful to you, or any more. is for the C compiler CCS, and i think is the way to do it so easy

The #USE RS232 (and I2C for that matter) is in effect for GETC, PUTC, PRINTF and KBHIT functions encountered until another #USE RS232 is found.



The #USE RS232 is not an executable line. It works much like a #DEFINE.



The following is an example program to read from one RS-232 port (A) and echo the data to both the first RS-232 port (A) and a second RS-232 port (B).



#USE RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1)

void put_to_a( char c ) {

put(c);

}

char get_from_a( ) {

return(getc()); }

#USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3)

void put_to_b( char b ) {

putc(c);

}

main() {

char c;

put_to_a("Online\n\r");

put_to_b("Online\n\r");

while(TRUE) {

c=get_from_a();

put_to_b(c);

put_to_a(c);

}

}



The following will do the same thing but is more readable and is the recommended method:



#USE RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1, STREAM=COM_A)

#USE RS232(BAUD=9600, XMIT=PIN_B2, RCV=PIN_B3, STREAM=COM_B)



main() {

char c;

fprintf(COM_A,"Online\n\r");

fprintf(COM_B,"Online\n\r");

while(TRUE) {

c = fgetc(COM_A);

fputc(c, COM_A);

fputc(c, COM_B);

}

}


this code came into the help of the compiler, searching as tag 'stream'
  Trả Lời Với Trích Dẫn