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 check the status of an output?

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



Joined: 18 Jul 2006
Posts: 98

View user's profile Send private message

How do I check the status of an output?
PostPosted: Tue Sep 09, 2008 2:47 pm     Reply with quote

I am converting some very old code that was written years ago in Microchip's now obsolete 8-bit C-Compiler.

In this old code I would have an ouput that will be turned off and on during the course of operation.

Depending on the state of this output I will do other things.

I would define the output as follows
Code:
#define RED_LED      PIN_C2


Then later in the program I would check the state of the output with a simple if statement like so
Code:
if(RED_LED == OFF) red_led_off_time++;


Is there a simple way to check the state of the outputs using the PCM 3.249 compiler?

Thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 2:56 pm     Reply with quote

The function input_state() will test the current voltage at the I/O pin without changing the TRIS setting.
Code:
void main()
{
  int8 count;
 
  output_high(PIN_B1);
  if (input_state(PIN_B1) == 1)
    count++;
}
edbfmi1



Joined: 18 Jul 2006
Posts: 98

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 7:22 pm     Reply with quote

Thank you! That is what I was looking for.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 3:45 am     Reply with quote

why is in my old manual for the compiler v3 written the following for the "input_state" function:
Quote:
Bit specifying whether pin is input or output. A 1 indicates the pin is input and a 0 indicates it is output.


cheers
Ttelmah
Guest







PostPosted: Wed Sep 10, 2008 4:32 am     Reply with quote

The current manual, has it as:
"Bit specifying whether pin is high or low. A 1 indicates the pin is high and a 0 indicates it is low", then:
"This function reads the level of a pin without changing the direction of the pin as INPUT() does."

Which is exactly what is wanted.

In fact, if you look in the 'readme.txt' with your compiler, it should have the updated definition. The manual was wrong for the first few versions after the function was launched.

Best Wishes
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 6:15 am     Reply with quote

you are absolutely right.
thanks, M.
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