PIC24F digital lines I/O...need help

Discussion in 'Embedded Systems and Microcontrollers' started by puneetnepsam, May 27, 2009.

  1. puneetnepsam

    Thread Starter New Member

    May 12, 2009
    5
    0
    hi i am a beginner in the embedded systems.....please help

    in the I/O ports section i have read.....
    TRIS register means that it will define the direction of the pin which is connected to the particular port
    exmple:

    TRISGbits.TRISG1 = 1 will make that line in the input mode...

    but what does
    PORTGbits.PORTG1 = 1;
    and
    LATGbits.LAT1 = 1;

    means??

    does it mean that it would write 1 to the corresponding line??

    thanks
    Puneet Gupta
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    What programming language and compiler are you using?
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    As you have surmised PORTGbits.PORTG1 = 1; writes a 1 to port G bit/pin 1 and
    LATGbits.LAT1 = 1; writes a 1 to latch G bit 1.

    In the case of writing, the two instructions are interchangeable but if you were doing a read then there can be significant differences between reading a port (pin) and reading the contents of the port data latch.
     
  4. houta69

    New Member

    Mar 8, 2009
    4
    0
    The rule of thumb is to write to the LAT register and read from the PORT register to avoid read-modify-write problems of writing directly to the PORT. Check out section 12.2.2 of the PIC24F family reference manual for the details.
     
  5. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    houta69;

    I think you have it the wrong way around.

    To quote from the ref manual section 12.2.3

    To prevent the read, modify, write problem you read from the latch and write where-ever you like since when you write to the port you are actually writing to the latch.
     
  6. houta69

    New Member

    Mar 8, 2009
    4
    0
    Greetings AlexR -

    This subject comes up at least once a month on the MCP forums. Here's a recent example.

    There's also a wiki link embedded in that thread that covers the topic.
     
Loading...