View previous topic :: View next topic |
Author |
Message |
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
How do I check the status of an output? |
Posted: Tue Sep 09, 2008 2:47 pm |
|
|
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
|
|
Posted: Tue Sep 09, 2008 2:56 pm |
|
|
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: 103
|
|
Posted: Tue Sep 09, 2008 7:22 pm |
|
|
Thank you! That is what I was looking for. |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Wed Sep 10, 2008 3:45 am |
|
|
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
|
|
Posted: Wed Sep 10, 2008 4:32 am |
|
|
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
|
|
Posted: Wed Sep 10, 2008 6:15 am |
|
|
you are absolutely right.
thanks, M. |
|
|
|