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

Difference between input_state() and input() - Uses of each

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



Joined: 29 Aug 2012
Posts: 17

View user's profile Send private message

Difference between input_state() and input() - Uses of each
PostPosted: Wed Aug 29, 2012 8:49 pm     Reply with quote

I am using a PIC 16f877 and PIC C compiler to program it. I know that the function
Code:
input_state()
does not change the state of the pin. However I am a bit curious regarding the working of
Code:
input()
function. Suppose we monitor a pin using input example
Code:
input(PIN_A0)
. I observed that this function changes the state of the pin to a 0 logic. So I wanted to know when should we use
Code:
input_state()
and when should we use
Code:
input(PIN_A0)
. What is the difference between them ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19349

View user's profile Send private message

PostPosted: Thu Aug 30, 2012 1:46 am     Reply with quote

Quote:

input(PIN_A0)
. I observed that this function changes the state of the pin to a 0 logic. So I wanted to know when should we use


Er. No.

This changes the state of the pin to be an input (1 in TRIS). It'll only go to logic '0', if there is circuitry outside that pulls the pin low. The pin itself is undriven.
Normally, when you 'read' a pin, you want to know what is being applied to it, from an external source. Hence you'd use 'input', and use the pin as an input. 99% of the time, you input, from pins programmed as inputs.

input_state, reads the logic level 'on' the pin, leaving the TRIS unchanged.

Times you might want this are:
1) You have the pin driving into something like a capacitor, and want to know 'when' it charges to a logic 0/1, while keeping the charging enabled.
2) You have a pin being changed in another separate piece of software, and it is not written to pass the value to you.

99% of the time you should use input.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Aug 30, 2012 11:06 am     Reply with quote

however TRIS is not changed when

#USE FAST_IO

has been declared.

under that condition: input(pin_xx)
just reads the digital state of the pin - the same as input_state() would, PROVIDING that YOU actually set TRIS =1 for that pin when you programmed it all.
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