LAT replaces PORT command?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Location
    Spain, Castellon
    Posts
    8

    Default LAT replaces PORT command?

    I regularly come back to designing fairly simple PIC projects, normally after long breaks, and I think I may have missed something whilst away. I am using a 18F device for the first time, and as usual did the first program to turn a load of LED's on and off, to make sure my hardware was working. I spent two days trying to do this, with the ports not behaving correctly at all, with LED's not turning on or off as they should, and me stating to think there was bugs in my programming software/hardware. In a moment of desperation, I started googling and up came a web site (I think the guys name was Bruce from rentron?) which spoke about replacing (for example) the PORTA command with the LATA command, this solved my problem instantly. I had never heard of the LAT command before, and it aint in my copy of the MELabs PicBasic Pro Compiler book. Is there any down side to just replacing all PORT commands with LAT commands? I tried searching in this forums search box, but nothing comes up for "LAT". Your help would be appreciated.

    Running PBP V2.6
    MicroCode Studio+
    MPASM V8
    Mark in Spain

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: LAT replaces PORT command?

    It is all clearly explained in the device data sheet - with further clarification in the MCHP Family Reference Manual.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: LAT replaces PORT command?

    PORTx and LATx are not commands, they are registers (basically RAM location in the PIC).

    Because of the way the PIC works internally (using a read-modify-write cycle) and depending on what the output pins are driving you can get the problem you had. Writing to the port latch (LATx) instead of directly to the port (PORTx) avoids the problem because the read-operation of the read-modify-write cycle is then performed agains the port latch instead of against the actual output pins.

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts