View previous topic :: View next topic |
Author |
Message |
Guest
|
PIC16F877 + USB |
Posted: Tue Feb 23, 2010 3:57 pm |
|
|
Hi everyone
I am having a project with PIC16F877. I want to use ex_usb_serial.
My question: Does this example support PIC16F877? If yes, I hope if
there is any illustration about this example, but if it did not support it, I
hope to you can tell me any way how to make it. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 23, 2010 4:02 pm |
|
|
The ex_usb_serial.c example does not support the 16F877.
It supports the 18F4550. You should buy that PIC. Then you
can test the example code. |
|
![](templates/subSilver/images/spacer.gif) |
microp
Joined: 23 Feb 2010 Posts: 6
|
|
Posted: Tue Feb 23, 2010 4:47 pm |
|
|
thanx for ur reply
Is there any other way to do that. |
|
![](templates/subSilver/images/spacer.gif) |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Tue Feb 23, 2010 11:20 pm |
|
|
Not directly. You can use interface chips from FTDI quite readily, though. They connect to the PIC via a serial port. |
|
![](templates/subSilver/images/spacer.gif) |
microp
Joined: 23 Feb 2010 Posts: 6
|
|
Posted: Wed Feb 24, 2010 1:01 am |
|
|
Thank you for your reply John.
I have one last question. How can I make 2 serial ports in the PIC16F877 in code?
I want to use the default serial for tx/rx from the camera and the assigned serial to send data to PC. |
|
![](templates/subSilver/images/spacer.gif) |
husam
Joined: 17 Feb 2010 Posts: 10 Location: jordan
|
hi microp |
Posted: Wed Feb 24, 2010 11:02 am |
|
|
try this example for pic 16f877a
Code: |
// for transmitter
#include <16f877a.h>
#fuses xt,NOWDT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_D0, rcv=PIN_D1, STREAM=COM_A, DISABLE_INTS)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, STREAM=COM_B, DISABLE_INTS)
void main()
{
set_tris_b(0x00);
output_b(0x00);
while(TRUE)
{
if (input(PIN_A0)) // for port d rs232
{output_high(PIN_B0);// sending started
fprintf(COM_A,"ABC");
delay_ms(1000);
output_low(PIN_B0);// sending end
}
if (input(PIN_A5))// for port c rs232
{output_high(PIN_B0);// sending started
fprintf(COM_B,"xyz");
delay_ms(1000);
output_low(PIN_B0);// sending end
}
}}
|
and for receiver
Code: |
#include <16f877a.h>
#fuses xt,NOWDT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_D0, rcv=PIN_D1, STREAM=COM_A,DISABLE_INTS)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, STREAM=COM_B,DISABLE_INTS)
/*
** kbhit() function return 1 when data deliverd to rx in pic
**in this case no need for interrupts
*/
int i;
int1 flag;
char RX[10] ; // if the array size doesn't enough the All data will be lost
void Zizo() // data delivered to port d
{
output_high(PIN_B0);// data comes right now
RX[i++] = getch(COM_A); // we use RX[i++] instead of for loop to save addresses in RX
flag=1;
delay_ms(100);
output_low(PIN_B0);// data end right now
}
void dodo() // data delivered to port c
{
output_high(PIN_B0);// data comes right now
RX[i++] = getch(COM_B); // we use RX[i++] instead of for loop to save addresses in RX
flag=1;
delay_ms(1000);
output_low(PIN_B0);// data end right now
}
void main()
{
while(TRUE)
{
if (kbhit(COM_A))
Zizo();
if (kbhit(COM_B))
dodo();
if(flag==1)
{ flag=0;
i=0;
}
if(RX[0]=='A') // by port d rs232
output_high(PIN_A0);
if(RX[0]=='x') // by port c rs232
output_high(PIN_A1);
}
}
|
i hope this helped you |
|
![](templates/subSilver/images/spacer.gif) |
microp
Joined: 23 Feb 2010 Posts: 6
|
|
Posted: Wed Feb 24, 2010 11:32 am |
|
|
Thanx husam I will try it and I will tell you the result.
Thanx again. |
|
![](templates/subSilver/images/spacer.gif) |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Wed Feb 24, 2010 3:30 pm |
|
|
Getting two software-based serial ports to work properly is extremely difficult, unless you have some way to be sure that only one of them sends data to the PIC at a time. You obviously can't allow one port to hog all the processor's time if the other one might be talking. Sending data out isn't much of a problem, as then the processor can control the timing. |
|
![](templates/subSilver/images/spacer.gif) |
microp
Joined: 23 Feb 2010 Posts: 6
|
|
Posted: Wed Feb 24, 2010 5:37 pm |
|
|
John i want one as Tx/Rx and the other just Tx |
|
![](templates/subSilver/images/spacer.gif) |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Thu Feb 25, 2010 6:56 pm |
|
|
I'm still not totally sure whether you intend to have two software-based serial ports, or just one along with another port made from the regular UART.
The trouble with having more than one half duplex port--whether you recieve or transmit--is that you may get the situation where the TX line is sending out a character, and while it's in progress, a character comes in on the RX line. One repetitive timer running at 9.6KB is easy enough, but syncing two (or more!) of them where the offset between the two is unpredictable, is just about impossible. I can imagine doing it with a ferociously fast timer at 4X the baud rate (38.4KB) and sampling the inputs plus sending out any outputs that may exist, but I'm not sure that's workable. The 16F877 may not be the right part for this job. |
|
![](templates/subSilver/images/spacer.gif) |
microp
Joined: 23 Feb 2010 Posts: 6
|
|
Posted: Fri Feb 26, 2010 10:05 am |
|
|
John I think you are right but that depends on the application.
I need one serial to send & rec. from camera and the other serial to send the stream to the PC. On my project I think that depends on the camera if I send a sequence of bits to it & if it sends back some of data not all of it, I can synchronize the operation easily without any issues.
But if the camera send all data one time I need an external memory to
store it. After it finish streaming I will send all data to PC. I think this is only the solution.
I hope if anyone got another solution to put it here. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Feb 26, 2010 10:18 am |
|
|
Do a search here.
I have in the past posted the core of a 'timer interrupt' based software serial.
With this, it is possible to code two full duplex serial streams if needed.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
microp
Joined: 23 Feb 2010 Posts: 6
|
|
Posted: Fri Feb 26, 2010 10:21 am |
|
|
thanx Ttelmah for your reply.
I will do the search. |
|
![](templates/subSilver/images/spacer.gif) |
husam
Joined: 17 Feb 2010 Posts: 10 Location: jordan
|
|
Posted: Fri Feb 26, 2010 10:25 am |
|
|
hi,
Check this site
http://www.electronics123.com/s.nl/it.A/id.2825/.f
It has suitable camera which can easily interface with pic & you can also
control the baud rate for the camera. The output of camera is a group of
packages can be stored using malloc() function then to mmc or external eeprom.
Quote: |
but if the camera send all data one time I need an external memory to
store it after it finish streaming I will send all data to PC. I think this is
only the solution. |
I think it will work but you have to consider 1: use big memory to store
the data from camera [200KByte or more] 2: check the clock frequency
of eeprom to avoid loss of data because of different speed [clock freq.
must be => baud from camera]. |
|
![](templates/subSilver/images/spacer.gif) |
|