|
|
View previous topic :: View next topic |
Author |
Message |
Andy
Joined: 18 Sep 2003 Posts: 1 Location: Wales
|
Kbhit and Streams and the old forum posts |
Posted: Wed Jan 14, 2004 6:44 am |
|
|
How do I check for a Kbhit on a stream. There is a link to the old forum www.pin-c.com/forum/general/posts/11111.htm but I just get 404 error. Are the old post zipped up somewhere, or does anyone have a copy of how to check kbhit on a stream. I'm using PCM ver 3.169.
Thanks for you help
Andy |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Jan 14, 2004 8:29 am |
|
|
Hi Andy,
Just a small push to start with:
Code: |
#define SPEED1 19200
#define SPEED2 9600
#define Xtal 20000000
#use delay(clock=Xtal, RESTART_WDT)
#use rs232(baud=SPEED1,xmit=PIN_C6,rcv=PIN_C7,stream=COM1,errors)
#use rs232(baud=SPEED2,xmit=PIN_B1,rcv=PIN_B0,stream=COM2)
//NOTE: To generate a software UART and the corresponding interrupt, rcv pin must be the external interrupt pin in the microcontroller you are using.
//Using hardware UART:
enable_interrupts(INT_RDA);
//Using software UART:
enable_interrupts(INT_EXT);
ext_int_edge( H_TO_L );
....
//In your #INT_RDA
....
if (kbhit(COM1))
{
BUFFER_1[i1] = fgetc(COM1);
i1++;
}
....
//In your #INT_EXT
....
if (kbhit(COM2))
{
BUFFER_2[i2] = fgetc(COM2);
i2++;
}
|
Hope this is what you need.
Best wishes,
Humberto |
|
|
rrb011270
Joined: 07 Sep 2003 Posts: 51
|
|
Posted: Wed Jan 14, 2004 5:06 pm |
|
|
Humberto wrote: | Hi Andy,
Just a small push to start with:
Code: |
#define SPEED1 19200
#define SPEED2 9600
#define Xtal 20000000
#use delay(clock=Xtal, RESTART_WDT)
#use rs232(baud=SPEED1,xmit=PIN_C6,rcv=PIN_C7,stream=COM1,errors)
#use rs232(baud=SPEED2,xmit=PIN_B1,rcv=PIN_B0,stream=COM2)
//NOTE: To generate a software UART and the corresponding interrupt, rcv pin must be the external interrupt pin in the microcontroller you are using.
//Using hardware UART:
enable_interrupts(INT_RDA);
//Using software UART:
enable_interrupts(INT_EXT);
ext_int_edge( H_TO_L );
....
//In your #INT_RDA
....
if (kbhit(COM1))
{
BUFFER_1[i1] = fgetc(COM1);
i1++;
}
....
//In your #INT_EXT
....
if (kbhit(COM2))
{
BUFFER_2[i2] = fgetc(COM2);
i2++;
}
|
Hope this is what you need.
Best wishes,
Humberto |
Mabuhay!
Is it possible to combine both the kbhit() function and the circular buffer method in an interrupt driven hardware uart?
Thanx |
|
|
hillcraft
Joined: 22 Sep 2003 Posts: 101 Location: Cape Town (South africa)
|
Another idea |
Posted: Thu Jan 15, 2004 12:20 am |
|
|
After much stuffing about with kbhit() on different streams I ended up using kbhit() for the HW UART and purely looking for input() on the RX pin. |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Mon Nov 10, 2008 2:10 am |
|
|
Quote: |
#use rs232(baud=SPEED1,xmit=PIN_C6,rcv=PIN_C7,stream=COM1,errors)
#use rs232(baud=SPEED2,xmit=PIN_B1,rcv=PIN_B0,stream=COM2)
//NOTE: To generate a software UART and the corresponding interrupt, rcv pin must be the external interrupt pin in the microcontroller you are using.
|
Hi,
since that, is it impossible to create more than one UART (in full duplex) with a PIC that have just one External interrupt (like an 16F877) ?
thanks in advance for answering me. |
|
|
Ttelmah Guest
|
|
Posted: Mon Nov 10, 2008 3:55 am |
|
|
The software UART, does not support 'full-duplex', no matter how many interrupts are available....
The software UART, _only_ gives half-duplex operation. For full duplex, you need either an inbuilt hardware UART, or an external UART chip.
There are I2C UART's, supporting two channels, that can be connected to a single INT pin (and two pins for I2C). Look at the Philips SC16IS7 family.
Best Wishes |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Mon Nov 10, 2008 4:28 pm |
|
|
Ttelmah wrote: | The software UART, does not support 'full-duplex', no matter how many interrupts are available....
The software UART, _only_ gives half-duplex operation. For full duplex, you need either an inbuilt hardware UART, or an external UART chip.
There are I2C UART's, supporting two channels, that can be connected to a single INT pin (and two pins for I2C). Look at the Philips SC16IS7 family.
Best Wishes |
Hi Ttelmah,
Thank you for your explanations and advice,
I took a look to the Philips SC16IS7 family, here http://www.nxp.com/acrobat_download/literature/9397/75015669.pdf and I think this is overfeatured fot my application, (connect a master and two slaves using RS232.), you'll probably ask me why not using I2C ?, I would say: I don´t really know which is more suitable for my application, but since I´ll probably use a 16F628 as one of the slaves (the other is 16F876 and the master is a 16F877) , I can´t use the I2C.
I've found a tricky way to use the hard UART insted of Soft one (look at the last post):
http://www.ccsinfo.com/forum/viewtopic.php?t=34680&highlight=soft+uart
What would you say about it ? |
|
|
Ttelmah Guest
|
|
Posted: Tue Nov 11, 2008 3:16 am |
|
|
Perfectly 'good', but _only_ if nothing can come of the other 'stream', while you have it switched to the second job.
You also have to ask whether you really need full duplex?. If you are the 'master' device, and the bus design is in your hands, you can eiither add an extra line, if the slave neds to 'initiate' communication, with it signalling on this line that it wants you to talk to it, or make all transactions 'master triggered', which then only needs half duplex communication.
Seriously, why commit yourself to the selected chips?. I2C, would be a much easier cheaper, and faster way to do the local interconnects. Something like the 16F737, would be smaller than adding an extra multiplexer chip, cheaper, and give you the I2C connection. Your 876/877, already have both.
Best Wishes |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Tue Nov 11, 2008 4:17 pm |
|
|
Ttelmah wrote: | Perfectly 'good', but _only_ if nothing can come of the other 'stream', while you have it switched to the second job.
You also have to ask whether you really need full duplex?. If you are the 'master' device, and the bus design is in your hands, you can either add an extra line, if the slave needs to 'initiate' communication, with it signaling on this line that it wants you to talk to it, or make all transactions 'master triggered', which then only needs half duplex communication.
Seriously, why commit yourself to the selected chips?. I2C, would be a much easier cheaper, and faster way to do the local interconnects. Something like the 16F737, would be smaller than adding an extra multiplexer chip, cheaper, and give you the I2C connection. Your 876/877, already have both.
Best Wishes |
Hi Ttelmah,
thank you again.
Ttelmah wrote: |
You also have to ask whether you really need full duplex?. |
no, I can use the half duplex, my system is not so critical.
As I'll use PICs equipped with I2C (in fact a master and 3 slaves, not 2) ,I decided to use the I2C,
unfortunately, I have already finished to write a long code for hard UART communication between two of my PICs, using routines of CCS library (SISR.C and STISR.C,...kbhit(), getc(),...), also procedures for loading ,sending and receiving buffers that took me much time....
will I have to make this work again for I2C ?
about my project: I´m designing three boards :
Master:
- mother board ----- 16F877
Slaves:
- terminal (LCD+keypad)--- 16F876
- stepper motor -----16F876
- drop counter----16F876 (or 16F628). as I´m now looking for making an I2C network between my cards.
the four cards are not distant (less than 1m). |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Wed Nov 12, 2008 10:28 am |
|
|
hi again,
I forgot to ask about an important thing, can the I2C be used for a distant microcontrollers (about 3, 4 meters), is it vulnerable to noise and parasits for this distance ? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|