I found the following:
1. At initialization, you set the bit AS2 in register ASSR (ASSR = 0x08). This means you want the Timer2 to be clocked from TOSCs pins (PC6, PC7). But these pins are connected to LCD and therefore canot be clock sources.
2. Since you didn't clock Timer2, you cannot receive interrupts from this timer and absence of last LCD string with time confirms this.
3. It is not good practice to use library functions like sprintf in interrupt handlers - they take a lot of processor time (In my IAR it taken approx. 16000 cycles, taking into account that you use CodeWizard it can take more).
I'd like to propose the following. Don't set the AS2 bit in ASSR. Using the crystal of 4MHz interrupts from Timer2 will be every (256 * 128) / 4MHz = 1/122s seconds. Correct the interrupt handler in the following way:
Код
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
static unsigned char sec122; // 1/122 seconds
if(++sec122 > 122)
{
sec122 = 0;
if (++t.second==60) //keep track of time, date, month, and year
{
........
}
}
The next thing - do not use the 4MHz crystal in tasks where real time is needed. Try to use the 3.6864MHz and TCCR2 = 0x04; You'll get the exact 1/225 seconds timer2 interval:
Код
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
static unsigned char sec122; // 1/122 seconds
if(++sec225 > 225)
{
sec225 = 0;
if (++t.second==60) //keep track of time, date, month, and year
{
........
}
}