Hi,
i don´t know the dsPIC33FJ, but often modern controllers have built in pullup resistors.
This function often must be enabled by setup. Please read datasheet about port pin functions.
Your top picture shows the external hardware, like you use it with internal pullup.
*****
Usually the controllers have high output drive capability. Therfore using a pin as output may cause overload in port drivers.
Some can handle short circuit currents for a short time. But be sure that this is specified in the datasheet.
Others may be damaged immediately when you press a key,
and again others may overheat within several minutes.
I think it is not a good idea to setup the port as output insteqad of an external pullup.
But the datasheet will tell you.
********
The lower picture is a usual circuit if the controller has no internal pullup function.
****
You tried and said it didn´t work with setup as output. I don´t know how you triedthis and how you recognized that it does not work...
****
I can imagine a "non reliable" solution (not for industry, no high quality product..)... but I don´t reccomend this:
every time you read the button (and this shoud be timed about every 20 -50 ms)
* set the port to output HIGH
* wait one us
* set the output to HIGH Z, and immediately after that
* read the port input
How it works:
For a short time switch the port to output, if now the button is not pressed one will see VCC at the port pin, if the button is pressed the voltage will be low.
Now switch to HIGH Z. The capacitance of the traces, pin, button... will keep voltage some 10 us. so you can read in the buton value.
With the short pulses of less than 2 us every 20 ms you have good chance not to kill the output.
Also supply current is relatively low with this solution. Heating should not occur.
****
But again, i don´t reccomend this, because this is a very dirty solution.
Klaus