PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   English forum on PICs (http://www.picvietnam.com/forum/forumdisplay.php?f=53)
-   -   PIC 16F877 with 3 serial ports (http://www.picvietnam.com/forum/showthread.php?t=1269)

toufik 08-07-2007 07:00 PM

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.

namqn 09-07-2007 02:05 AM

Trích:

Nguyên văn bởi toufik (Post 9905)
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,

Khách 09-07-2007 05:51 AM

Trích:

Nguyên văn bởi namqn (Post 9919)
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

Toufik 09-07-2007 05:57 AM

Trích:

Nguyên văn bởi namqn (Post 9919)
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.

namqn 09-07-2007 07:17 PM

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,

Khách 09-07-2007 11:11 PM

Trích:

Nguyên văn bởi namqn (Post 9942)
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.

Toufik 09-07-2007 11:18 PM

PIC 16F877 with 3 serial ports
 
Trích:

Nguyên văn bởi namqn (Post 9942)
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

namqn 10-07-2007 12:09 AM

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,

linhnc308 06-10-2007 03:32 PM

Trích:

Nguyên văn bởi toufik (Post 9905)
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.

batinh 13-12-2007 10:14 PM

hi! when we use software RS232, can we use interrupt for receive data? i have used it, but not sussecc.
thanks for help.

ngochiep 14-12-2007 11:11 PM

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'.

ngochiep 14-12-2007 11:15 PM

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();
  }


Khách 10-08-2008 03:32 AM

Androisa
 
Trích:

Nguyên văn bởi toufik (Post 9905)
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'

ungthh30490 23-03-2010 07:14 PM

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

robotden 27-03-2010 08:14 PM

I can write 3 seria port for pic6f877a. I use software


Múi giờ GMT. Hiện tại là 09:20 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam