TRISA, TRISB setting ?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326

    Default TRISA, TRISB setting ?

    good day,
    I am using the pic 18f452 to acquire some analog signals, to activate some discretes, to read and write ext memory, to interface wuith the serial link and read discretes ( pushbuttons ) and I did not use the TRISA nor TRISB . The system works well.
    I will like to understand the real usage or when the TRISA TRISB need to be used in a picbasic pro programs.
    Thanks for the assistance,
    Regards,
    Ambrogio

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, Ambrogio

    May I suggest you to open your Holy Manual and just read the INPUT and OUTPUT commands pages ... a look to other commands pages will show you that PBP automatically sets inputs/outputs as desired ... or not !

    Alain
    Last edited by Acetronics2; - 10th January 2011 at 13:06.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default

    Hi,
    you mean the PBP manual ?
    tnks
    Ambro
    Quote Originally Posted by Acetronics View Post
    Hi, Ambrogio

    May I suggest you to open your Holy Manual and just read the INPUT and OUTPUT commands pages ... a look to other commands pages will show you that PBP automatically sets inputs/outputs as desired ... or not !

    Alain

  4. #4
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I found what you suggested to look_at.
    When a PIC MCU powers-up, all of the pins are set to input. To use a
    pin as an output, the pin or port must be set to an output or a command
    must be used that automatically sets a pin to an output.
    To set a pin or port to an output (or input), set its TRIS register. Setting a
    TRIS bit to 0 makes its corresponding port pin an output. Setting a TRIS
    bit to 1 makes its corresponding port pin an input.

    So, it is not needed to use tris register !
    Am I right ?

    Ambrogio

    Quote Originally Posted by Acetronics View Post
    Hi, Ambrogio

    May I suggest you to open your Holy Manual and just read the INPUT and OUTPUT commands pages ... a look to other commands pages will show you that PBP automatically sets inputs/outputs as desired ... or not !

    Alain

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Using many of the PBP commands as you are reading setting TRIS is not needed.
    But
    as time goes on and your code becomes more complex TRIS will need set. It will be good to get the habit of string TRIS now... or just wait until the code does not work and remember this.

    One example would be reading/writing to the port.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Does the problem arise if I do : high LED, low LED ... or.. If PB=1 then... If PB=0 then...
    Next: I2C requires a pin to be an output and an input for correct communication: what should I declare in the TRIS reg ?
    Thanks
    Ambrogio


    Quote Originally Posted by mackrackit View Post
    Using many of the PBP commands as you are reading setting TRIS is not needed.
    But
    as time goes on and your code becomes more complex TRIS will need set. It will be good to get the habit of string TRIS now... or just wait until the code does not work and remember this.

    One example would be reading/writing to the port.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, Ambrogio

    I' ve taken the good habit ALWAYS to set ALL my Inputs/Outputs with TRIS statements AND aet their respective default level in the first lines of my programs.
    of course, all SFR's and variables too ...

    Whether PBP ( or any other high level language ) does it for me or not ... so, I'm REALLY sure of what will happen. Especially @ Power-up.

    But you can do as you want ... there's no absolute rule !!!

    If PB=1 then... If PB=0 then...
    no automatic input setting here ... sooooo you could read an output state !!!

    Alain
    Last edited by Acetronics2; - 10th January 2011 at 16:08.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I2C requires a pin to be an output and an input for correct communication: what should I declare in the TRIS reg ?
    I2C is one of those commands that will set the TRIS for you. But like Alain said, you will want to control things at start up. I would set them as an input.

    If you have floating pins set them as out puts.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

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