Changing LED brightness using PIC 16F877A
Look up something called pulse width modulation, usually abbreviated PWM.

With PWM, you always switch the LED either full on or full off.  However, you do this so fast that a human looking at the LED only perceives the average brightness.

It only takes a few 10s of Hz to get to the point where you can't see the individual pulses when looking directly at the LED.  However, it will still flicker noticeably when you move your eyes.  It is usually good to use a few 100 Hz minimum PWM frequency for brightness-adjusting LEDs.  You can also soften the on/off transitions with added electrical components like capacitors and inductor.

The 16F877 has PWM generators built in.  Take a look at the CCP modules.  Once a CCP module is set up, all the firmware has to do is write a new duty cycle into the right register or registers to set the brightness.