1. 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.
    Dismiss Notice

Very confused about setting TRIS to output or input

Discussion in 'Microcontrollers' started by arlin, Jun 8, 2003.

  1. arlin

    arlin New Member

    Joined:
    May 26, 2003
    Messages:
    16
    Likes:
    0
    Hi, Newbie here.
    I am just starting with PIC programming and have come across something very confusing with PicBasic. From my reading it appears that by assigning 0 to a pin's Dir you make it an input and by assigning 1 you make it an output. (page 22 of the PicBasic manual)

    But then there is this code:
    Symbol TrisA = $85
    Poke TrisA,255 'make all portA pins inputs
    - aren't we assigning ones to the TrisA bit of each pin and shouldn't that make them outputs?
    Am I missing something here?
    This is really going to bug me; your input will really be appreciated.
     
  2. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA
    TrisA and TrisB are Port A & B direction registers which decide the direction of individual port pins depending upon the value in these registers.

    Unlike other microcontrollers, PICs port are a bit different. You need to set the direction in Tris register before doing any manipulations with the port pins.

    I think Tris activates/deactivates internal pull-up's or pull-downs on the port pins.
     
  3. arlin

    arlin New Member

    Joined:
    May 26, 2003
    Messages:
    16
    Likes:
    0
    Thanks for the input, Kinjalp. What is really confusing me is an apparent contradiction in my PicBasic manual regarding the particular values assigned to the Tris register that determine whether pins are inputs or outputs.
    .... and I just figured it out - the manual has it backwards. After looking at the 16f84 datasheet it appears that a value of one in the Tris bit makes it a input.

    How annoying! I'm sure you old pro's can spot a typo instantly, but as a newcomer to electronics I have spent hours scratching my head over something in a book or manual only to find that it is a typo or outright error.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA

    Thats correct. In 16F84, when you set a bit in TRIS, the corresponding pin will become input and vice-versa. I think there is a mistake in PICBASIC manual.

    See example on this page: http://microengineeringlabs.com/resources/pbcmanual/5/5-22.htm

    In this they have set the TRIS as per PIC16F84 datasheet, that means there is a goof-up in the manual.
     
  6. arlin

    arlin New Member

    Joined:
    May 26, 2003
    Messages:
    16
    Likes:
    0
    Thanks for the confirmation Kinjalgp. The error is in the area where they discuss the 'Dirs' variable.
     

Share This Page