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 do I get the status of an output pin?

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



Joined: 07 Sep 2009
Posts: 2
Location: Sweden

View user's profile Send private message

How do I get the status of an output pin?
PostPosted: Mon Sep 07, 2009 12:56 am     Reply with quote

I am new into CCS and I am using a PIC12F683. Reading the status of an input pin is no problem. But how can I read the status of an output pin? I know that I am controlling the pin, but if I want to do something only when the pin set to high. Like: "if (PIN_A0 = 1)"
Hope you understand what I mean.
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

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

PostPosted: Mon Sep 07, 2009 2:51 am     Reply with quote

I haven't really understood what exactly it is that you want to do. Almost all pins can be set as inputs or outputs. In more technical terms almost all pins have an input buffer and an output latch (there are a few pins which may be input-only). Have a look at this code segment:
Code:
output_high(pin_a0);
flag_var=input(pin_a0);
This first outputs a '1' onto pin A0, and then attempts to read the status of the same pin. This is all you require to do - the compiler does the hard work of changing the tristate register of the PIC. The above statements make the pin an output, and then change it to an input.

If you wish that the pin remain an output while you check its status, you want to use the statement:
Code:
input_state(pin_a0);
.

It is possible that you may encounter the 'Read-modify-write (RMW)' problem while using the 'output' statement.
http://www.ccsinfo.com/forum/viewtopic.php?t=36885&highlight=rmw

Rohit
sugarman64



Joined: 07 Sep 2009
Posts: 2
Location: Sweden

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 10:16 am     Reply with quote

This is exactly what I had problems with. Tried it in a simple piece of code and then it works. Thank you.
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