what kind of time scale do you need (ie how long on and off)? There are really 2 methods I can think of:
Timers and interrupts (using this Kevin
code as base)
User controlled custom PWMs (using this Kevin
code as base)
There is always good code at Kevin's
Repository.
Depending on your application one of these options is better. Can you explain your application more precisely?
NOTE: the interrupt code is old (last processor) but still decent for copying the the timers interrupt and initialization code