View previous topic :: View next topic |
Author |
Message |
rajeshkhan808
Joined: 29 Aug 2012 Posts: 17
|
Difference between input_state() and input() - Uses of each |
Posted: Wed Aug 29, 2012 8:49 pm |
|
|
I am using a PIC 16f877 and PIC C compiler to program it. I know that the function does not change the state of the pin. However I am a bit curious regarding the working of function. Suppose we monitor a pin using input example . I observed that this function changes the state of the pin to a 0 logic. So I wanted to know when should we use
and when should we use . What is the difference between them ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Aug 30, 2012 1:46 am |
|
|
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
|
|
Posted: Thu Aug 30, 2012 11:06 am |
|
|
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. |
|
|
|