dc motor and hung (not stable) pic
Federico Russo said it well: "decoupling, decoupling, decoupling". ICs like microcontrollers require smooth power supplies, that is without disturbances. Small negative spikes may cause a reset or cause your software to go bananas. Positive spikes may do the same, and even damage the part. You definitely want to get rid of those disturbances. There are two ways to attack the problem, and the best way is to apply both.  

First consider the cause of the disturbances. This is often difficult to find out, but in our case it's definitely the motor. Place capacitors between the power supply and ground, close to the motor's connection pins. Have an electrolytic capacitor of \$100\mu F\$ (actual value depends on the motor current, but this is a good start), and place a \$1\mu F\$ ceramic capacitor parallel to it. The latter is needed because the elco is not good at high frequencies, and there the ceramic takes over.
This is the first step. It's not just necessary to solve our problem, it also reduces EMI (ElectroMagnetic Interference). There are regulations about the level of EMI you may create.  

Then we go to the microcontroller. The power supply will not necessarily be clean yet, there may be other noise sources. Here we do the same: place capacitors on the power pins, between \$V_{DD}\$ and ground, as close as possible to the pins. The microcontroller doesn't use high current, so we won't need the \$100\mu F\$ elco. Usually a \$100nF\$ ceramic will do. To calm your nerves :-) you may add a \$1\mu F\$.
What else? Some other pins may also be sensitive to noise. Look at the reset pin. It's no good ensuring that your power supply is clean if the microcontroller would reset due to spikes on the reset pin. So also a cap between reset and ground, again as close as possible to the pin. \$100nF\$ is fine.