Hi there,
One way to do this is to sync the PIC to the line frequency via an input pin, sensing near to the zero crossing of the AC line.
You can then generate a delay of length up to the time for one half cycle of the line frequency. The shorter the delay the brighter the bulb, and the longer (up to the half cycle time limit) the dimmer the bulb will be. By varying the delay time the bulb can be dimmed to just about any level. At the end of the delay the triac gate is triggered so it turns the triac on. The triac turns off by itself at the zero crossing. In this way you generate pulses who's amplitudes vary with the line sine wave but are only as wide as one half the cycle time minus the delay time.
It's somewhat important that you dont allow the delay time to ever exceed the half cycle time or you'll end up with subharmonics which may make the bulb look like it is blinking sometimes as well as end up with other undesirable effects. One way to ensure this criterion is met is to set the max delay time to something like 95 percent of the time for one half cycle.