Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Timer ISR not working in LPC2148

Status
Not open for further replies.

akash.v

Newbie level 1
Joined
Jun 17, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
7
Hi,

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 there in the peripherals
checked the Timer0 block there TCR and TC registers are enabling
and resetting with the step by step execution.

Below is the part of the code added:

Code:
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

 }

void time_set(void)
{
    U32 timer = 0;
    unsigned char buf[16] = {0};
    sprintf((char *)buf, "Time=%02d:%02d  ",minutes_remaining,seconds_remaining);
    lcd_putstring(1, (char *)buf);
    minutes_remaining = minutes_selected;
        T0TCR = 1;
}

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)
        {
            time_set();
        }
    }
}


Please suggest me where i'm going wrong.

Regards,
akash
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top