This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer ISR not working in LPC2148

Hello,
Based on the example projects I tried working on timers in lpc2148
and set the time for 5 minutes duration to test, but it's not working.
So checked in the debug session in keil ide, and in the peripherals
checked the Timer0 block there TCR and TC registers are enabling
and resetting with the step by step execution.
I tried printing the string in the ISR to check whether it's working
or not but it's not printing the string passed.

Below is the code part:

void initClocks(void);
void initTimer0(void);
__irq void T0ISR(void);
void init_timer0(void);
void time_set(void);
unsigned char count_load;

volatile signed char seconds_remaining = 59;
unsigned int minutes_selected = 01;
unsigned char flag;


__irq void T0ISR(void)//__irq void tc0(void)
{
if(flag == 0)
    {
            if(T0IR == 0x01)
            {
            T0IR = 1;
        if((seconds_remaining == 0) && (minutes_remaining == 0))
        {
        minutes_remaining = 0;
        seconds_remaining=0;
        flag = 1;
                }
else if(seconds_remaining ==0)
                    {
            seconds_remaining = 59;
        minutes_remaining--;
                      }
else if(minutes_remaining == -1)
                    {
                    minutes_remaining = 59;
                    --hours_remaining;
                        }
                        else
                        {
                       seconds_remaining --;
            }
            show_time_flag = 1;
           }
        }
else
            {
            if((timer1_overflow_count % 10) == 0)
                  show_seconds_flag = 1;
            timer1_overflow_count++;
            if(timer1_overflow_count == 1200)
                  {
                    count_load = 1;
//                            T0TC = 0x00;
//                            T0PR = 0x01;
                        }
                }
        }



void init_timer0(void)
{
T0CTCR = 0x0;            //to enable for timer mode
/* since the timer will be only used as counter set the interrupt bit in IR to 0 */
T0IR = 0x01;            /* initializing all the Interrupt registers to zero so that no timer related interrupt is generated*/
T0PC = 0x01;
T0PR = 59999; //0x00E4E1C0/*
T0TCR = 0x01;          /* To enable timer '0'*/
T0MCR = 0x0003;    /* 0th bit indicates timer interrupt is enablled and 1st bit
                    sets to reset the timer TC0*/

T0MR0 = 0x05;            /* Match reg for generating timer interrupt*/
VICVectCntl4 = 0x20 | 4;                    // use it for Timer 0 Interrupt
VICVectAddr4 = (unsigned long)T0ISR;      // set interrupt vector in 0
VICIntEnable = 0x10;                    //Enable Timer0 ISR

 }

int main (void)
{
    init_lcd();
    initClocks();
    init_timer0();
    lcd_clear();
    flag=0;
    while(1)
    {
  if(show_seconds_flag == 1)
      {
            show_seconds_flag = 0;
              init_timer0();
    }
        while(1)
        {
     sprintf((char *)buf, "Time=%02d:%02d  ",minutes_remaining,seconds_remaining);
    lcd_putstring(1, (char *)buf);
    minutes_remaining = minutes_selected;
        T0TCR = 1;
        }
    }
}

Please suggest me where i'm doing wrong.

Regards,
Akash