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

How to use other pins as TX / RX ?

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



Joined: 23 Mar 2004
Posts: 6
Location: Belgium

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

How to use other pins as TX / RX ?
PostPosted: Fri May 21, 2004 10:17 am     Reply with quote

Hi, I'm using a 16F877 to communicate by RS-232. I can allready read and receive data by the special pins (RC7 & RC6), using putchar() and getchar().
The problem is that I'll have to receive and transmit ASCII characters by another ports (RD4 and RD5). To realise this I could allready send characters (a string...) by printf("Test");, just before I put
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_D4,rcv=PIN_D5) to define the port.
How can I detect characters? Is their a way to use a funcion same as getchar() like scanf()?
Maybe I'll have to "cheat" the PIC that the other port (RD4 and RD5) works as a RS-232 one (TX/RX). Do I have to configure it in a special way?
Thanks for your time!
_________________
Yves Willemaers
Belgian student
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri May 21, 2004 11:38 am     Reply with quote

You should define the two ports with stream names. Then when you wish to use printF you can use FprintF with a stream name. The same for using putC and GetC change them to FputC and FgetC.
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Fri May 21, 2004 11:46 am     Reply with quote

since there is only the one hardware uart on the chip, there is only one receive interrupt.. you will have to rig somethign up with external interrupts to clock data in on the software uart
Ttelmah
Guest







Re: How to use other pins as TX / RX ?
PostPosted: Sat May 22, 2004 9:34 am     Reply with quote

chancaar wrote:
Hi, I'm using a 16F877 to communicate by RS-232. I can allready read and receive data by the special pins (RC7 & RC6), using putchar() and getchar().
The problem is that I'll have to receive and transmit ASCII characters by another ports (RD4 and RD5). To realise this I could allready send characters (a string...) by printf("Test");, just before I put
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_D4,rcv=PIN_D5) to define the port.
How can I detect characters? Is their a way to use a funcion same as getchar() like scanf()?
Maybe I'll have to "cheat" the PIC that the other port (RD4 and RD5) works as a RS-232 one (TX/RX). Do I have to configure it in a special way?
Thanks for your time!

There are two fundamentally different ways of handling serial I/O. With the first, hardware exists in the chip, to generate all the required timings, and a hardware shift register receives/transmits the character.
Using this, there is an interrupt when the transmit 'buffer' becomes full, and another when the receive buffer becomes full, and the code can test to see if a character is waiting, by simply checking the status of this buffer flag.
The second way, is to do the entire transmission/reception in software. This is what happens when any pins other than those designated for the hardware UART(s) are selected. Now transmission is not that different (provided you don't have any interrupts running - if an interrupt occurs from another source during character transmission, there will be timing errors on the character). However reception, requires that the code is 'polling' the pin, waiting for the character to arrive, or characters will be lost. There is a method round this, if you are using a relatively slow data rate, on a fairly fast chip. Here you can designate the 'receive' line, as one that supports hardware interrupts. Then call an interrupt handler when the line falls, and in the interrupt handler, call 'getc' for the corresponding stream, which will wait for the character. The 'downside' of this, is that the code will sit in this interrupt handler for the entire duration of the character (typically 10 bit times).
For the general question, about how to call 'getc' for a different port, another has allready answered, with the 'key' that the simplest way is to use 'streams'. The other answer is to have multiple #use RS232 statements. technically, getc, putc etc, when used without a stream designator, allways use the _last_ #use RS232 definition passed in running the code. Hence you can have a subroutine to fetch a character on a 'software' port, that as it's first line has the RS232 definition for the software port, then ends with the one to reselect the hardware port. Calling the routine, will make getc temporarily refer to the soft port.

Best Wishes
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