PIC controller doubt about programming

Discussion in 'Embedded Systems and Microcontrollers' started by embpic, Jun 2, 2014.

  1. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    i am confuse when using PORTBbits.xxx and LATBbits.xxx resister.
    when i used this words PORTBbits then structure get dropdown type come out.
    so what is used for what i am really confused.

    [​IMG]
     
  2. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    so when to use RB0 and when to use TRISB0.
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    For 18F and enhanced midrange:

    The TRIS registers set the direction of the port pin 1=IN, 0=OUT. Writing TRIS is usually done during power up initialization.

    PORT and LAT refer to the IO pins themselves. For inputs always read PORT and for writes (including bit set/clear) specify LAT to avoid read-modify-write problems. (PORT and LAT refer to the same pin but work differently to handle these different actions). Never bsf/bcf PORTx always bsf/bcf LATx.

    Many pins have multiple functions that must be considered. For example, some are ANALOG on power up and must be explicitly configured to be a digital port.

    The IO chapter in the databook covers all of this in detail, providing tables of shared functions and registers used to configure the ports.
     
    Last edited: Jun 2, 2014
  4. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    yes sir this is clear but when i type in editor as:
    TRISBbits. then what should i select whether
    Code ( (Unknown Language)):
    1. TRISBbits.RB0
    or

    Code ( (Unknown Language)):
    1. TRISBbits.TRISB0
     
  5. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    It looks likely they are both 0-7 range, so they will both work the same.

    However I would still use;
    TRISBbits.TRISB0
    because it is not possible to confuse that with something else.
     
  6. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    And sir what about LATBbits
    it is also same i think.
    Code (Text):
    1. LATBbits.LATB0
     
  7. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,605
    A complete answer would require knowing what compiler and what device you are using, as these symbols are defined inside the dot h file the compiler supplies for each device.

    However, for a PIC18 device under XC8 you could use either the TRISB0 or the RB0.

    Additionally, I agree with RB here, TRISB0 is preferable for readability for reasons of tradition at the very least.
     
Loading...