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