How to enable pull resistors in HCS08 is pretty much undocumented in the manual. What you have to do is this:
- Write to PTnPS to enable interrupts. Yes, it doesn't make sense. But it will enable the next register, PTnES.
- Write to PTnES to select interrupt edge trigger. Yes, it doesn't make sense. But it will at the same time set the pull resistor polarity: pull-up or pull-down.
- Write to PTnPE to enable the pull resistor.
- Write zero to PTnDD to set the pin as input.
---
That being said, your code has the following problems:
- You aren't using any contact de-bouncing. You need some form of simple contact de-bouncing algorithm, or your program will read random inputs from the switch.
- You are using the bitwise operators incorrectly. To check if a port input is set, you should have written PTDD_PTDD2 & 0x02, meaning "if the port AND the value 0x02 gives me 0x02 rather than 0x00 as result, then...". Similarly you are setting the output incorrectly, it should have been PTFD_PTFD0 |= 0x01; // set to pin to 1, or PTFD_PTFD0 &=~0x01; // set pin to 0.
Also, you seem to be using Freescale's default register map with non-standard bit-fields. Since that crappy register map isn't written in standard C, nobody knows what will happen when you write 0x02 to a single bit, the C standard doesn't document or specify it. I would personally stick to C instead of using Freescale non-standard features.