Are you connecting Mosfet to common cathodes or anodes and driving the mosfet from PWM ?
If yes, map the Led data bus data to pwm duty.
Edit:
If you have 8 Leds and their cathodes are shorted and connected to drain of Mosfet and Mosfet source is grounded and gate is connected to PWM output then
For 8 LEDs duty is 100% = 255 in mikroC
For 0 LEDs duty is 0% = 0
y = mx + c
duty = m * 8 + 0
255 = m * 8
m = 255 / 8
= 31.875
duty = no. of leds On * 31.875
map the mask value to no. of leds On in switch statement and accordingly assign duties