We want to be able to design a PIC microcontroller based timer. The specification requires that we have a time for at least one month (30 days). I have been trying to figure out how one can do that but I am stuck. Any suggestions please?
How accurate does this 30 day period have to be? 30 days is about 2.5 million seconds, with a crystal accuracy of 20 ppm you might have a one minute error after 1 month.
If a one minute error is unacceptable you could use a temperature controlled oscillator or a better crystal, like 5 ppm. If external aid is allowed you could use the signal of a DCF77 receiver (Europe, WWVB for North-America). These will give you a tick per second with atomic clock precision. All you have to do is count pulses. Note that DCF77 has only 59 pulses per minute, the omitted pulse indicates the start of a new minute. If you take this into account your 30 day period has elapsed after 2 548 800 pulses (59 \$\times\$ 60 \$\times\$ 24 \$\times\$ 30).
If the PIC has to do it all by itself that shouldn't be a problem either. Clock at 32768 Hz and program a timer to give an interrupt after 32768 clock cycles, that's one second. Count 2 592 000 interrupts (60 \$\times\$ 60 \$\times\$ 24 \$\times\$ 30).
In a month a lot can happen, and you probably want a battery backup in case there's a power outage. If you use the atomic clock signal you can also decode the time code after each minute pulse and compare date and time with your target time. In that case power outages don't even matter.
edit 2 (re Olin's comment)
edit 3 (re your comment on accuracy)
PICs don't have oscillators with 30 day periods built in, but you can very easily make one from a faster oscillator by counting cycles. You start with a faster clock you do have available, like the instruction clock or a external timer 1 oscillator. You can use a timer to reduce this clock to a low enough frequency so that it is reasonable to interrupt on it or even just poll for a new cycle in the foreground code.
For example, you can easily generate periods of 1000s of instruction cycles using timer 2 and its dedicated period register, prescaler, and postscaler. You didn't say what PIC you had in mind, so I'll assume a normal PIC 16 or PIC 18. You use a counter in RAM you manage from firmware to divide the rest of the way. For example, if the PIC will be doing other things, it's often convenient to set up a periodic 1 ms interrupt using timer 2. The interrupt routine could generate multiple ticks, like 10 ms, 100 ms, and 1 second, 1 minute, 1 hour, and 1 day. Then you count 30 1-day ticks. This method requires only a single byte for each divider in the chain and makes sense when the other ticks are useful too. If the other ticks are of no use, you could just count 2,592,000,000 millisecond ticks, which requires 4 bytes.
If low power is important and the PIC can sleep a good fraction of the time during the 30 days, then connect a 32768 Hz watch crystal to timer 1 and have the PIC wake up every 2 seconds when the timer overflows. Count 1,296,000 timer 1 overflows to get 30 days. That requires 21 bits, so only 3 bytes of RAM.