Configure a PIC pin for Input and Output
Change the pin configuration every time.  It's the TRIS register that controls if it's an input (1) or output (0).  And, when you change direction, you have to wait a moment (check the datasheet) like a cycle or two before you use that pin.  a couple Nop(); will do fine.

And, make sure you write to the LAT register, and read from the R register.

e.g.
for port D, pin 0.

//output
_TRISD0 = 0;
Nop();
Nop();
_LATD0 = 1;
_LATD0 = 0;


//input
_TRISD0 = 1;
Nop();
Nop();
int i = _RD0;