CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Kbhit and Streams and the old forum posts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Andy



Joined: 18 Sep 2003
Posts: 1
Location: Wales

View user's profile Send private message

Kbhit and Streams and the old forum posts
PostPosted: Wed Jan 14, 2004 6:44 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 14, 2004 8:14 am     Reply with quote

Try these links:

http://www.ccsinfo.com/forum/viewtopic.php?t=17927&highlight=kbhit+stream

this might be useful also:

http://www.ccsinfo.com/forum/viewtopic.php?t=17854&highlight=kbhit+stream
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Jan 14, 2004 8:29 am     Reply with quote

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

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Jan 14, 2004 5:06 pm     Reply with quote

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)

View user's profile Send private message Send e-mail Visit poster's website

Another idea
PostPosted: Thu Jan 15, 2004 12:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 10, 2008 2:10 am     Reply with quote

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) ? Rolling Eyes


thanks in advance for answering me.
Ttelmah
Guest







PostPosted: Mon Nov 10, 2008 3:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 10, 2008 4:28 pm     Reply with quote

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, Smile

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







PostPosted: Tue Nov 11, 2008 3:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 11, 2008 4:17 pm     Reply with quote

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 ? Rolling Eyes


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

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 10:28 am     Reply with quote

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 ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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