Input and Output on same Port


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2008
    Posts
    39

    Default Input and Output on same Port

    Ok this may seem like a silly question, but I want to use one port to input data and output data, PortE actually on an 18f8722. Now I know that TRISE $FF will make PortE and Input and TRISE=$00 Will make it an output, but what do I use for both??

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Remember that a 1 in a TRIS setting will make the pin an INPUT (remember 1=I=Input), and a zero will make it an Output (remember 0=O=Output).

    So, TRISE=$FF is the same as TRISE=%11111111 (all input)

    and TRISE=$00 is the same as TRISE=%00000000 (all output)

    so to make bits 0 thru 3 INPUT and bits 4 thru 7 OUTPUT you can write...

    TRISE=$0F or TRISE=%00001111

    and to make all even bits INPUT and all odd bits OUTPUT...

    TRISE=$55 or TRISE=%01010101

    and to make pin E.2 and E.7 INPUT, and all the rest OUTPUT...

    TRISE=$84 or TRISE=%10000100

    etc etc.

  3. #3
    Join Date
    Aug 2008
    Posts
    39


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply. I understand the 1 and 0 of each port, but in a portion I want it all an input and later on I want it all and output.

    Do I have to have a TRISE $00 before I use it as an output, and then have another TRISE $FF to use it as an input??

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Precisely.

    If you wish to use a pin (or indeed an entire Port) for Input and Output, all you do is simply change the TRIS for that pin or that whole Port before you perform any I/O.

    Once you set TRIS, it stays that way until you change it. Note that some PBP commands change TRIS on pins as required by that command, but for clarity, you should always set TRIS for whatever you happen to need it for.

    There is no restriction as to how many times you can change the TRIS status within your program.

Similar Threads

  1. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  2. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29
  5. Duplicating port input to port output
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th April 2004, 21:43

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