PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > English forum on PICs

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

English forum on PICs Forum for foreigners -only English in this forum - Do not need to register or login

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
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
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 08:59 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam