View previous topic :: View next topic |
Author |
Message |
Guest
|
reading the output latch...??? |
Posted: Mon Feb 08, 2010 5:19 pm |
|
|
Hi all,
I'm sure this has been covered before but I haven't managed to find it. I want to be able to read the current value of (for example) Port A of my PIC. After I do output_A(val);, I'd like to be able to 'query' the output value at a later time. Is this possible, or would I just have to keep track of the value in my code, and assume that the PIC output would never differ??
Thanks,
Joe |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 08, 2010 5:35 pm |
|
|
It depends on the PIC. That's why you should always post your PIC.
If you have an 18F PIC, it has a Latch register which you can read.
If you have a 16F PIC, it doesn't have the latch registers. It only has
the Port registers. Reading a Port register will not necessarily give
you the value that you wrote to it. External circuits on the pins can
load down the pins. You could write a '1', but read a '0'. If you use
18F and take care to read the Latch register (and not the Port), then
you eliminate this problem. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Feb 09, 2010 7:28 am |
|
|
One should clarify exactly what you want to read. Do you want to read what you previously wrote to the port? Or do you want to read the current state of the port? The latter can be useful, for example to detect a shorted pin or other hardware fault. Examine the data sheet for your PIC. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Guest
|
|
Posted: Tue Feb 09, 2010 9:53 am |
|
|
Hi all,
Good point, it's a PIC 16F882, so it looks like it's only got a 'port' register, and no 'latch' register.
I really only want to read what's been previously written to the port. The outputs are buffered, so the port register will most likely be a valid representation of the outputs. On the other hand, there is no reason the outputs would change after they are written, I just thought an independent 'query' might be useful.
Thanks,
Joe |
|
|
|