Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PORTx or LATx

Status
Not open for further replies.
When LATx is read it returns the value that was last written to the port.
When PORTx is read it returns the value that is on the pins, even if the pin is set to output.

So, when setting or clearing an output pin use LATx. When testing an input pin use PORTx.

The difference is subtle but can cause problems.
For example,
If you have a capacitive load on bit 3 of a port and do the following sequence,
bsf PORTx,3
bcf PORTx,4
then the capacitive load on bit 3 may not have charged yet and when the processor reads the port during the bcf, it will read bit 3 as low and will subsequently write it back as 0. By using LATx this problem doesn't occur.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top