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

16F877A port c as output or input and also rs232? output_c()

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



Joined: 08 Nov 2005
Posts: 28

View user's profile Send private message

16F877A port c as output or input and also rs232? output_c()
PostPosted: Sun Jun 04, 2006 12:24 pm     Reply with quote

Something wrong with input at port c also

Code:

while(1) {
      newval=input_c();
      if (newval!=oldval) {
         oldval=newval;
         printf("%03u|",newval);
      }     
   }


This one works like a interrupt functions. If any changes occur, the value will be sent to the pc.

But there are always changes, because port c's pin c6 and c7 are used as rs232.

What do i need to do to prevent input_c() from reading the state of c6 and c7?

-----------------------------------------------------------

I use port c as output and c6 and c7 as rs232.

When i call

output_c(0);

the rs232 stops responding.

do i need to use

set_tris_c(0xC0);

or something else to use the function output_c()?


Last edited by leesing2k3 on Sun Jun 04, 2006 6:48 pm; edited 2 times in total
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Sun Jun 04, 2006 1:10 pm     Reply with quote

There are a couple of things you need to do. The CCS function output_c() will override and overwrite whatever the USART is doing and thereby destroy your RS232 comms.

The first thing you need to do is tell the compiler that you'll handle the tris (direction) of port C yourself. Unless you specify that you're handling the tris registers yourself, the compiler automatically sets the direction of a port based on whether you're reading from it or writing to it. Near the top of your program, you'll need this line:

Code:
#use fast_io(C)


Then you'll need to set the tris register for port C. C7 is rx (input), C6 is tx (output). If you want the rest of the port's pins to be outputs, you'll need so set the tris as:

Code:
set_tris_c(0x80);


To write to port C all at once basically involves some manipulation. Before doing a write to port C, read it first. You'll need to use the #byte directive to associate a variable with the port C data latch register in the processor's memory. For the 877A, port C lies at address 0x07. In your program you'll need:

Code:
#byte portc = 0x07


The basic idea is:

Code:
current_rs232 = portc & 0xc0;  // read port c to find out what C6 and C7 are
new_portc = 0; // this is necessary to make sure bits 6 & 7 are 0...
new_portc = my_portc_data | current_rs232; //...otherwise this OR won't work
portc = new_portc; // finally write out what you want, while not disturbing what C6 and C7 are OR:
output_c(new_portc); // this will do it too


Hope this helps.
leesing2k3



Joined: 08 Nov 2005
Posts: 28

View user's profile Send private message

PostPosted: Sun Jun 04, 2006 1:16 pm     Reply with quote

Thank you very much.
leesing2k3



Joined: 08 Nov 2005
Posts: 28

View user's profile Send private message

PostPosted: Sun Jun 04, 2006 6:49 pm     Reply with quote

Something wrong with input at port c also

Code:

while(1) {
      newval=input_c();
      if (newval!=oldval) {
         oldval=newval;
         printf("%03u|",newval);
      }     
   }


This one works like a interrupt functions. If any changes occur, the value will be sent to the pc.

But there are always changes, because port c's pin c6 and c7 are used as rs232.

What do i need to do to prevent input_c() from reading the state of c6 and c7?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Sun Jun 04, 2006 7:29 pm     Reply with quote

Code:

while(1) {
      newval=input_c() & 0x3f; // note change here
      if (newval!=oldval) {
         oldval=newval;
         printf("%03u|",newval);
      }     
   }
leesing2k3



Joined: 08 Nov 2005
Posts: 28

View user's profile Send private message

PostPosted: Sun Jun 04, 2006 7:32 pm     Reply with quote

Thank you very much again
leesing2k3



Joined: 08 Nov 2005
Posts: 28

View user's profile Send private message

PostPosted: Sun Jun 04, 2006 7:36 pm     Reply with quote

newguy wrote:

The first thing you need to do is tell the compiler that you'll handle the tris (direction) of port C yourself. Unless you specify that you're handling the tris registers yourself, the compiler automatically sets the direction of a port based on whether you're reading from it or writing to it. Near the top of your program, you'll need this line:

Code:
#use fast_io(C)


Do you mean

Code:
#use fixed_io(C)


or

Code:
#use fast_io(C)


?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Sun Jun 04, 2006 7:41 pm     Reply with quote

fast_io. The manual lists the differences between the different io modes. I always use fast_io - preference/habit really.
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