This is how you control motors:
http://www.societyofrobots.com/schematics_h-bridgedes.shtmlIf your motor is small enough, you can also get a motor driver IC. It does not require you to PWM it.
To PWM, all you do is this:
bring a digital port high
wait 1 milisecond (or whatever time)
bring a digital port low
wait 1 milisecond (or whatever time)
loop
Chances are you have sample code to turn on/off an LED? Its exactly the same code, just the loop goes really really fast.