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 CCS Technical Support

Question about use pin as uart rcv port and normal input.

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



Joined: 03 Dec 2008
Posts: 45

View user's profile Send private message

Question about use pin as uart rcv port and normal input.
PostPosted: Wed Apr 14, 2010 9:26 am     Reply with quote

I used pic16f84a.
I want to use pin_b2 as uart receiving port, and normal output pin during a loop. I set
Code:
#use rs232 (baud=9600,xmit=pin_b1,rcv=pin_b2)

at the beginning of the program. Do I need to do something before I let
pin_b2 be as normal input pin in that loop ? And after that do I need use
Code:
#use rs232 (baud=9600,xmit=pin_b1,rcv=pin_b2)

to let this pin be as a uart receiving port again ?
I appreciate any response in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 11:56 am     Reply with quote

I'm not sure why you want to do this, because if you have the PIC
and a MAX232 both driving the same line, then you can have a
conflict. It's possible that some damage could occur to the chips.

But anyway, here is how you can find the answer:

Make a small test program that only tests your desired feature.
In the Project Options, put the .LST file format into Symbolic format.
This will make it easier to read. Then compile the program and look
at the .LST file:

In this part, we see that the compiler sets the TRIS for pin B2 to be
an output pin. That is normal.
Code:

.................... c = getc();
0030:  CALL   @GETCH_1_
0031:  MOVF   @0D,W
0032:  MOVWF  c
.................... output_low(PIN_B2);
0033:  BSF    STATUS.RP0
0034:  BCF    TRISB.2         // Set TRISB.2 = 0 (set as output pin)
0035:  BCF    STATUS.RP0
0036:  BCF    PORTB.2
.................... c = getc();
0037:  CALL   @GETCH_1_
0038:  MOVF   @0D,W
0039:  MOVWF  c


In the RS232 library code, CCS sets pin B2 to be an input pin, before
it executes the RS232 code for getc(). So it will work OK for RS232.
So the answer is, no, you don't need to use another #use rs232()
statement each time. Just use one statement.
Code:

.................... #use rs232 (baud=9600,xmit=pin_b1,rcv=pin_b2) 
0004:  BSF    STATUS.RP0
0005:  BSF    TRISB.2       // Set TRISB.2 = 1 (set as input pin)
0006:  BCF    STATUS.RP0
0007:  BTFSC  PORTB.2
0008:  GOTO   007
0009:  MOVLW  08
000A:  MOVWF  @0C
000B:  CLRF   @@12
000C:  BSF    @0C.7
000D:  GOTO   01C
.
.
.


Here is the test program:
Code:

#include <16F84a.H>
#fuses XT, NOWDT
#use delay(clock=4000000)
#use rs232 (baud=9600,xmit=pin_b1,rcv=pin_b2)

//========================================
void main()
{
char c;

c = getc();
output_low(PIN_B2);
c = getc();

while(1);
}
cchappyboy



Joined: 03 Dec 2008
Posts: 45

View user's profile Send private message

PostPosted: Thu Apr 15, 2010 12:04 pm     Reply with quote

Thank you so much. By the way, where can i get the library code such as rs232 or something else supplied by ccs.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 15, 2010 12:12 pm     Reply with quote

The C source code is not available for the #use rs232() library.
CCS does not supply it.

If you want to understand the library code, you can look in the .LST file.
It shows the ASM code for the #use rs232() library.

Also, here is some C source code that duplicates the function of the
#use rs232() library.
http://www.ccsinfo.com/forum/viewtopic.php?t=26631&start=8
However, it's preferable that you use the library code. The code above
was only intended to help someone who had a buggy version of the
compiler.
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