I too am confused by this. JPortici has pretty much covered everything (PPS to assign PWM output pins, use of interrupts etcc).
The only things I'll add are about using PWM for your backlight.
If the display has an LED backlight that is directly powered (or switched with an NPN transistor) then ideally you want a PWM frequency of > 500Hz. Many say you 'can't detect 100Hz' but you can, especially if your gaze moves across the display (turning your head). Even at 500Hz, at low duty (say 10%) one may detect some flicker because it is at the lowest duty that there is the largest gap between LED on times.
This can also be overcome by using more complicated versions of PWM rather than the standard 'Output on when timer = 0, output off when timer = period'. I won't go into detail because I believe you can use your hardware PWM's which can easily provide >1kHz period with >10 steps (a lot more, should you want it).
If the backlight is powered by a boost converter - some backlights are LED's in series requiring up to 28V - and it as a 'PWM dimming' pin, then the PWM frequency range depends on this boost.
10 steps is a reasonable resolution for controlling a backlight. Often people go overboard with 8-bit (256 steps) up to 12-bit (4096) but that is only really required for colour mixing or fading.
Finally, there are a number of ways to implement one or more PWM's using timers, interrupts (as well as of course the hardware PWM) and yours appears to be needlessly complicated - although looks like it will work exactly how you want to it. The downside of course is for each PWM 'step' the interrupt must fire that number of times per PWM period. So for 100Hz - PWM period of 10ms, if you want 10 levels, your interrupt must fire every 1ms.
A better method would be to calculate the on/off time, and set the timer to fire the interrupt after these times. For example, for 200Hz, period =- 5ms. For 10 steps, that is 500us resolution.
For duty = 40%. Get 40% of 5ms = 5*0.4 = 2ms. On-time = 2ms. Of time = period - on-time = 5-2 = 3ms. You calculate on_time and off_time each time you change the period. All this does is set the timer to fire after 'off_time' if the output is on, and 'on_time' if the output is off.
Interrupt pseudocode:
if(output_on) {
output_on = 0;
output_pin = 0;
timer_period = off_time;
}
else {
output_on = 1;
output_pin = 1;
timer_period = on_time;
}
This way, the interrupt is only called twice per PWM period. But it only works for one PWM - your method would be more appropriate for multiple PWM's of the same period.
Edit: westfw beat me to it :/ This is why I should 'review' my reply when posts were made whilst I was replying