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

reading the output latch...???

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








reading the output latch...???
PostPosted: Mon Feb 08, 2010 5:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 08, 2010 5:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 09, 2010 7:28 am     Reply with quote

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








PostPosted: Tue Feb 09, 2010 9:53 am     Reply with quote

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
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