No one can give you C code for that without knowing the uC family.
Also, what is so hard about it? A duty cycle of 0% = completely off, 100% duty cycle = completely on, and in-between adjusts the intensity. The other factor depends on your hardware design -- the ballast resistor will determine the current and thus the brightness throughout the range.