Not using a PIC, but this is generally the circuit that I use. I use an opto for zero crossing and a MOC3021 to trigger the TRIAC. Andrew Kilpatrick » Interfacing: AC Line
I know this doesn't help any, but the programming really became clear and easy when I was able to look at what was happening with a scope. You are able to change the trigger timing, watch it on the scope and watch how it effects the AC load, in my case Christmas lights. Oddly, the uC I was using was triggering on both rising and falling edge when it should not have been and I still have not figured out why, but I have a workaround.
The only issue is since most houses wel.. outlets where you get mains from are not uniform meaning the lines are sometimes reversed on the outlet... does it matter which is NUET and which is HOT since its AC?
So triacs are normally off. And since at the Zero point it turns off again (if on) we should turn it on a certain amount of time before the zero time ... like a auto PWM correct?
So if its off as normal and a Zero Point is sensed then i delay a short while before turning the gate OPEN then it will close again on zero point then i can repeat with different delay times to achieve different brightness levels.
The only issue is since most houses wel.. outlets where you get mains from are not uniform meaning the lines are sometimes reversed on the outlet... does it matter which is NUET and which is HOT since its AC?