I wrote ( nearly wrote ) a timer - relay system for a job once... It never came off. It was written for the pic18f452, an is almost complete... It does, however, contain ALL the code for time and alarm setting and control for 8 relays....
There are routines for everything LCD, keypad, outputs I2C memory I2C RTC .....
(I must point out, these routines are written for MY board, and so the code is hardware written...)