Here you will find an example of a code for 8051 on PWM controlled LEDs: https://www.iguanalabs.com/pwm.htm
There will be scores of other examples but I think this one is one of the simples and most comprehensive desription of PWM using basic 8051 (without built-in PWM block) ..
As you probably know, some of 8051 microcontrollers have a PWM module built in. In this case control of this module is relatively simple.
If you would like to compare more examples on PWM and 8051, do you prefer pure 8051-core (software PWM) or 8051 derivatives with buil-in PWM module (hardware solution) ?
... some of 8051 microcontrollers have a PWM module built in ... do you prefer pure 8051-core (software PWM) or 8051 derivatives with buil-in PWM module (hardware solution) ?