I need to switch between RS485 signal and Digital input port
This should be straightforward:







simulate this circuit &ndash; Schematic created using CircuitLab

When the RS-485 driver is disabled, you can read the pins directly. I would add some buffers to protect the MCU inputs from direct connection to the outside world.

There is the small matter of RS-485 bus termination, if used. You can get driver/receiver chips that include switchable termination.