Jump to content
Sign in to follow this  
TomF

Reading And Writing Lat Or Port

Recommended Posts

Hi,

 

Are the following 4 statements true for a device that implements 'lata' and 'porta', rather than only 'porta'

 

 

1. Write to LAT (which then gets written to PORT)

 

2. Read from LAT if pin is output (read what you set in 1. above)

 

3. Read from PORT if pin is an input (read input from external hardware)

 

4. Reading from LAT when pin is an input always reads as '0'

 

 

 

 

?

Share this post


Link to post
Share on other sites
Hi,

 

Are the following 4 statements true for a device that implements 'lata' and 'porta', rather than only 'porta'

 

 

1. Write to LAT (which then gets written to PORT)

There is no 'which then gets written'. All writes to either goto LATx and appear on output pins immediately.

2. Read from LAT if pin is output (read what you set in 1. above)
Yes.
3. Read from PORT if pin is an input (read input from external hardware)
Yes.
4. Reading from LAT when pin is an input always reads as '0'

No. LATx always reads as the last value written to it.

 

You need to read section 11.1.2 Output Data Latches (LATx) and Data Direction Register (TRISx)

of the PIC18 family reference manual DS39500A.

 

Meanwhile, the attached image may help!

post-5160-1313079877_thumb.png

Edited by IanM

Share this post


Link to post
Share on other sites
No. LATx always reads as the last value written to it.

Not always strictly true. To quote from PIC18F4520 datasheet:

Pins RA6 and RA7 are multiplexed with the main oscillator pins; they are enabled as oscillator or I/O pins by the selection of

the main oscillator in the configuration register (see Section 23.1 “Configuration Bits” for details). When they are not used as

port pins, RA6 and RA7 and their associated TRIS and LAT bits are read as ‘0’.

Hope that helps

 

davidb

Share this post


Link to post
Share on other sites

Goes with: Unimplemented pins read as '0', and is almost certainly for backwards compatibility.

 

Thanks - its a useful correction.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...