Switch gpio between input and output

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Beertree
Posts: 24
Joined: Wed Apr 29, 2015 4:49 pm
Has thanked: 5 times
Been thanked: 5 times
Contact:

Switch gpio between input and output

Post by Beertree »

Hello there,
I am using a Pic18 for my project. One pin needs to be switched between input and output mode during operation. How do i realise that?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Switch gpio between input and output

Post by LeighM »

In most cases you can simply mix use of both the "Input" icon and the "Output" icon on the Flowchart, the code generated will swap the I/O direction for you.

Beertree
Posts: 24
Joined: Wed Apr 29, 2015 4:49 pm
Has thanked: 5 times
Been thanked: 5 times
Contact:

Re: Switch gpio between input and output

Post by Beertree »

Thank you, for your fast reply. What will happen, if ill set an output to high state and then use it as an input and ask for its status. Will the pin stay high?
Regards

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Switch gpio between input and output

Post by LeighM »

That depends upon what you have connected to it.
I think you need to explain in a bit more detail what you are trying to do, and what electronic components you have attached to this I/O pin, e.g. a circuit diagram

Beertree
Posts: 24
Joined: Wed Apr 29, 2015 4:49 pm
Has thanked: 5 times
Been thanked: 5 times
Contact:

Re: Switch gpio between input and output

Post by Beertree »

Ok. The pin is conected to a display/touch module. During startup the state of the connected pin on the the display has to be active low. After startup procedure the display module signals on that same pin with a active low state, if there has been a touch action. So my question is: if i put that pin of the mc in a certain state, then later use it as an input and ask for its state, will i get the status of the connected display or the status i put in the pin before when it was still an output.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Switch gpio between input and output

Post by LeighM »

It sounds like the module has an open collector/drain type I/O then, if so, if you use an input macro you will get the status of the connected display

Beertree
Posts: 24
Joined: Wed Apr 29, 2015 4:49 pm
Has thanked: 5 times
Been thanked: 5 times
Contact:

Re: Switch gpio between input and output

Post by Beertree »

Thank you, that solved my problem

Post Reply