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

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 08-07-2007, 07:00 PM   #1
toufik
Guest
 
Bài gửi: n/a
PIC 16F877 with 3 serial ports

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.
  Trả Lời Với Trích Dẫn
Old 09-07-2007, 02:05 AM   #2
namqn
Trưởng lão PIC bang
 
Tham gia ngày: Feb 2006
Nơi Cư Ngụ: Tp. HCM, Việt Nam
Bài gửi: 3,025
:
Send a message via Yahoo to namqn
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.
What kind of equipment do you want to control with PIC16F877?
Is it necessary to use RS-232 serial ports? Could you use other serial protocols such as I2C, SPI?
What is the requirement of the communication speed, data rate?

Cheers,
__________________
Biển học mênh mông, sức người có hạn.

Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau:
http://www.picvietnam.com/forum/showthread.php?t=1263
namqn vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 09-07-2007, 05:51 AM   #3
Khách
Guest
 
Bài gửi: n/a
Trích:
Nguyên văn bởi namqn View Post
What kind of equipment do you want to control with PIC16F877?
Is it necessary to use RS-232 serial ports? Could you use other serial protocols such as I2C, SPI?
What is the requirement of the communication speed, data rate?

Cheers,
If the other serial protocols can do the job, it is ok to use them.
the equipements are: Multimeter with serial port rs232, it can be adjusted on the following coniguration:Baud rates:9600, 4800, 2400, 1200, 300
Format: 8 bits no parỉty, or 7 bits even parity
Stop bit: Always 1
  Trả Lời Với Trích Dẫn
Old 09-07-2007, 05:57 AM   #4
Toufik
Guest
 
Bài gửi: n/a
Trích:
Nguyên văn bởi namqn View Post
What kind of equipment do you want to control with PIC16F877?
Is it necessary to use RS-232 serial ports? Could you use other serial protocols such as I2C, SPI?
What is the requirement of the communication speed, data rate?

Cheers,
If the other serial protocols can do the job, it is ok to use them.
the equipements are: a Barometer and a Multimeter with serial port rs232, it can be adjusted on the following configurations:
Baud rates:9600, 4800, 2400, 1200, 300
Format: 8 bits no parỉty, or 7 bits even parity
Stop bit: Always 1
Can I use I2C or SPI?
Thanks in advance for any help you can provide.
  Trả Lời Với Trích Dẫn
Old 09-07-2007, 07:17 PM   #5
namqn
Trưởng lão PIC bang
 
Tham gia ngày: Feb 2006
Nơi Cư Ngụ: Tp. HCM, Việt Nam
Bài gửi: 3,025
:
Send a message via Yahoo to namqn
If the equipments use RS-232, then the only way to talk to them is via RS-232. That's fine. Your problem can be solved in different ways, depending on the data rate you need.

The baud rate is your communication speed, not the data rate. The data rate is how frequent you want your data. If your data rate is low, like 10 samples/second, then you probably can use some multiplexer to connect the equipments and the host PC to the PIC one-by-one.

If the data rate is high and/or control action is fast, then you probably need a couple of PICs connected together. They can talk to each other via different protocols.

Cheers,
__________________
Biển học mênh mông, sức người có hạn.

Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau:
http://www.picvietnam.com/forum/showthread.php?t=1263

thay đổi nội dung bởi: namqn, 09-07-2007 lúc 11:28 PM.
namqn vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 09-07-2007, 11:11 PM   #6
Khách
Guest
 
Bài gửi: n/a
Trích:
Nguyên văn bởi namqn View Post
If the equipments use RS-232, then the only way to talk to them is via RS-232. That's fine. Your problem can be solved in different ways, depending on the data rate you need.

The baud rate is your communication speed, not the data rate. The data rate is how frequent you want your data. If your data rate is low, like 10 samples/second, then you probably can use some multiplexer to connect the equipments and the host PC one-by-one.

If the data rate is high and/or control action is fast, then you probably need a couple of PICs connected together. They can talk to each other via different protocols.

Cheers,
Thank you very much for your answer, but i want to know how can i do to use the multiplexer to connect the equipments (Multimeter, Barometer) and the card(the card with PIC16F877 to control 2 stepper motors) and the host PC one-by-one.
Do you have a schematic for that? thanks in advance.
  Trả Lời Với Trích Dẫn
Old 09-07-2007, 11:18 PM   #7
Toufik
Guest
 
Bài gửi: n/a
PIC 16F877 with 3 serial ports

Trích:
Nguyên văn bởi namqn View Post
If the equipments use RS-232, then the only way to talk to them is via RS-232. That's fine. Your problem can be solved in different ways, depending on the data rate you need.

The baud rate is your communication speed, not the data rate. The data rate is how frequent you want your data. If your data rate is low, like 10 samples/second, then you probably can use some multiplexer to connect the equipments and the host PC one-by-one.

If the data rate is high and/or control action is fast, then you probably need a couple of PICs connected together. They can talk to each other via different protocols.

Cheers,
Thank you very much for your reply, but I want to know how to do to use the multiplexer to connect the equipments, the card (the card with pic16f877 to control 2 stepper motors) and the host PC one-by-one, do you have a schematic for that please.
Thanks in advance
  Trả Lời Với Trích Dẫn
Old 10-07-2007, 12:09 AM   #8
namqn
Trưởng lão PIC bang
 
Tham gia ngày: Feb 2006
Nơi Cư Ngụ: Tp. HCM, Việt Nam
Bài gửi: 3,025
:
Send a message via Yahoo to namqn
For RX signal of PIC, you will need a 3-to-1 multiplexer. For TX signal of PIC, you will need a 1-to-3 demultiplexer.

Have a look at the following links:
http://www.play-hookey.com/digital/m...our_input.html
http://www.play-hookey.com/digital/d...emux_four.html

Remember that you would need 3 separate level shifters (MAX232, for example) in total, when you use commercial multiplexer/demultiplexer chips (because they are logic chips).

Sorry I don't have time to create a schematic for you!

Cheers,
__________________
Biển học mênh mông, sức người có hạn.

Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau:
http://www.picvietnam.com/forum/showthread.php?t=1263
namqn vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 06-10-2007, 03:32 PM   #9
linhnc308
Đệ tử 5 túi
 
Tham gia ngày: Oct 2005
Bài gửi: 117
:
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.
I know your problem and your expect. So, you can refer to CCS Compiler for PIC. With its RS232 function, you can create maximum up to 5 serial port (one is force HW and anothers is SW RS232).

Syntax:
#use rs232 (options)

Elements:
Options are separated by commas and may be:

STREAM=id
Associates a stream identifier with this RS232 port. The identifier may then be used in functions like fputc.

BAUD=x >> Set baud rate to x

XMIT=pin >> Set transmit pin

RCV=pin >> Set receive pin

FORCE_SW >> Will generate software serial I/O routines even when the UART pins are specified.

Example:

#use rs232(Stream = HWRS232,9600,xmit = PIN_C6,rcv = PIN_C7) // #1 HW
#use rs232(Stream = SWRS232_1,9600,xmit = PIN_B0,rcv = PIN_B1) // #2
#use rs232(Stream = SWRS232_2,9600,xmit = PIN_B2,rcv = PIN_B3) // #3
#use rs232(Stream = SWRS232_3,9600,xmit = PIN_B4,rcv = PIN_B5) // #4

/* In your program, when you want to send some data to your specification rs232 port, use function fputc(), fgetc(), fprintf()
*/
fprintf(HWRS232,"This is 1st 232 Port");
fprintf(SWRS232_1,"This is 2st 232 Port");
fprintf(SWRS232_2,"This is 3st 232 Port");
fprintf(SWRS232_3,"This is 4st 232 Port");

I used this method for my project, expand from 1 RS232 port to 4 RS232 port using PIC16F876A. For the successfull with this, please refer to HELP of CCS to get more informations.
Good luck.
__________________
CallerID, Ethernet-RS232, PICWEB, Cảnh báo BTS
Giải pháp toàn diện giám sát - điều khiển từ xa qua GSM/Internet
0988006696

http://linhnc308.blogspot.com
linhnc308@gmail.com
linhnc308 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 13-12-2007, 10:14 PM   #10
batinh
Nhập môn đệ tử
 
Tham gia ngày: May 2006
Bài gửi: 7
:
hi! when we use software RS232, can we use interrupt for receive data? i have used it, but not sussecc.
thanks for help.
batinh vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 14-12-2007, 11:11 PM   #11
ngochiep
Nhập môn đệ tử
 
Tham gia ngày: Nov 2007
Bài gửi: 3
:
chuong trinh dieu khien 8 led don dung ngon ngu ccsc don gian de hieu
Chương trình điều khiển 8 led chớp tắt dùng PIC16F877A viết bằng C:
Code:
//================================================= =======
// Ten chuong trinh : Mach test den chop tat tren PORTB
// Nguoi thuc hien : abc
// Ngay thuc hien : dd/mm/yyyy
// Mo ta phan cung : Dung PIC16F877A - thach anh 20MHz
// : LED giao tiep voi PORTB
// : Cuc duong cua LED noi voi Vcc
// : RB0 - RB7 la cac chan output
//================================================= =======
#include <16f877a.h>
#include <def_16f877a.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, PUT, NOPROTECT,  NOLVP
#use delay(clock=20000000)
void main()
{
// Thiet lap che do cho PORTB
TRISB = 0x00;		 		// Tat ca PORTB deu la cong xuat du lieu
PORTB = 0xFF; 				// Tat het cac LED
While(1)
{
PORTB = 0; 			// Cho các LED sáng
delay_ms(500); 			// Tạo thời gian trễ 500ms
PORTB = 0xFF;			// Cho các LED tắt
delay_ms(500);			// Tạo thời gian trễ 500ms
}
}
namqn: Bạn nhớ viết bài bằng tiếng Việt có dấu, nếu không chúng tôi sẽ phải chuyển bài của bạn vào luồng 'Những bài viết không rõ ràng'.

thay đổi nội dung bởi: namqn, 15-12-2007 lúc 01:23 AM.
ngochiep vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 14-12-2007, 11:15 PM   #12
ngochiep
Nhập môn đệ tử
 
Tham gia ngày: Nov 2007
Bài gửi: 3
:
Smile DONG HO SO gui moi nguoi tham khao

Code:
THIEÁT KEÁ ÑOÀNG HOÀ SOÁ DUØNG PIC 16F877A 
//*Write         :
//*Hardware      :PIC16f877A
//*Compiler      :CCS C
//*=========================================
#include<16F877A.h>
#include<def_16F877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(b)
#use fast_io(d)

int8 i,dvis,chucs,dvim,chucm,dvih,chuch;
int32 a,b;
int32 h,k;
int32 bien;
const unsigned char dig[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

void hienthi()
{
   i=0;
   while(i<24)
   {
      portd=0xfe;
      portb=dig[dvis];
      delay_us(6900);
      portd=0xfd;
      portb=dig[chucs];
      delay_us(6900);
      portd=0xfb;
      portb=dig[dvim];
      delay_us(6900);
      portd=0xf7;
      portb=dig[chucm];
      delay_us(6900);
      portd=0xef;
      portb=dig[dvih];
      delay_us(6900);
      portd=0xdf;
      portb=dig[chuch];
      delay_us(6900);
      i++;
   }
}

void chuyendoi()
{
   b=a/3600;
   a=a%3600;
   h=a/60;
   a=a%60;
   k=a;
   chucs=k/10;
   dvis=k%10;
   chucm=h/10;
   dvim=h%10;
   chuch=b/10;
   dvih=b%10;
}

void main()
{
   trisb=0x0;
   trisd=0x0;
   bien=0;
   while(1)
   {
      bien=bien+1;
      if(bien==86400)
      {
         bien=0;
      }
      a=bien;
      chuyendoi();
      hienthi();
   }

thay đổi nội dung bởi: namqn, 15-12-2007 lúc 01:24 AM.
ngochiep vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
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
Old 23-03-2010, 07:14 PM   #14
ungthh30490
Nhập môn đệ tử
 
Tham gia ngày: Mar 2010
Bài gửi: 2
:
hi!!! mình có tài liệu về PIC 16F87x các bạn có thể download về tham khảo:
http://www.ziddu.com/download/912306...gviet.pdf.html
ungthh30490 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 27-03-2010, 08:14 PM   #15
robotden
Đệ tử 5 túi
 
robotden's Avatar
 
Tham gia ngày: May 2007
Bài gửi: 102
:
I can write 3 seria port for pic6f877a. I use software
__________________
Thật bó tay!
robotden vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lời


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à 07:06 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