|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
how know the state of a output |
Posted: Wed Nov 22, 2006 3:52 am |
|
|
Hi
I would like to know the state of a output for example
PIN_A0=!PIN_A0;
and what means #define PIN_A0 41 ? is it a adress in the .h or parameter for the different function?
is it necessary to know his state it whitout use pointer? |
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 22, 2006 4:17 am |
|
|
Not a simple answer to these...
The define 'means' nothing really. It is an internal 'coding' value, used by the compiler to tell _it_ what bit you are referring to.
It is actually defined as the port address of the I/O register, times 8, plus the bit number of the required bit.
Now, the commands to access the bits, are 'input', and 'output'. So you can 'read' the value on the pin, with 'input(PIN_A0)', and write a value to the output, with 'output(PIN_A0)'. There is however a big 'caveat' here. Unless you specify 'fixed_io' mode, or 'fast_io' mode, the compiler will switch the logic feeding the pin to 'input mode', as soon as you perform an input, and 'output mode' when you perform an output.
Hence to actually read the voltage 'on' the pin without this change, requires that _you_ change operating mode to one of the fixed modes, and you can then read the pin without this happening. You can also get the same effect by directly accessing the port without using the inbuilt driver functions.
The next part depends on what PIC is involved. The fact that the define you list for the pin is a low number, implies this is probably a 16 family chip. On these there is no ability to actually 'look' at the output driver, without physically reading the pin. On the latter 18 family chips, the output 'drive' register, is independant of the port itself, and on these, you can read this register to see what value is being 'sent' to the port, independant of what voltages are actually 'on' the port at present.
Best Wishes |
|
|
Guest
|
|
Posted: Wed Nov 22, 2006 4:54 am |
|
|
Is it really necessary to use the function set_tris_X? because the compiler will switch the logic feeding the pin to 'input mode', as soon as you perform an input, and 'output mode' when you perform an output. |
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 22, 2006 5:23 am |
|
|
To actually 'read' an output pin, without changing it to an input, requires the following:
fixed_io mode, or fast_io mode.
In the latter, setting TRIS.
Then reading the pin.
The automatic 'tris', is exactly the problem.
If you perform the test in the form originally posted (just adding the input/output instrutions), the pin will be changed to being an _input_ for the test. If you want to leave the driver driving, it needs to remain as an output...
Best Wishes |
|
|
|
|
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
|