sorry, I misread your email and just noticed you needed a c program. I don't have an 8051 C compiler so I can't help with the program.
As to the 555, it's a completely different solution. It would work if the timing is approximate but if you need accurate timing a 555 won't work. The crystal timing in a microprocessor would be much better, but a diode, resistor and optoisolator would produce a square wave from AC, even 120VAC, which could be counted for perfectly accurate timing.