Hi guys , here I am posting the code which I used to make a simple LED blinking program using TIMERS on Mega162 uC using WINAVR. This program is not working, so anyone help me in fixing it up-------

This is the code for which I have used the AVRLib library----

#include "io.h"
#include "timer.c"
#include "timer.h"
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>

#define TIMER_VALUE 175

unsigned int ctr;

void function1(void)
{
TCNT0=TIMER_VALUE;
ctr++;
}

int main()
{
DDRA=0xff;
PORTA=0xaa;

timerInit();
timerAttach(TIMER0OVERFLOW_INT,function1);
timer0SetPrescaler(5);
TCNT0=TIMER_VALUE;

for(;
{
if(ctr==5)
{
PORTA^=0xff;
ctr=0;
}

}
return 0;
}


This code I have used without AVRLib library----


//Mega162 running @ 8 MHz


#include "io.h"
#include <inttypes.h>
#include <avr/sfr_defs.h>
#include <avr/signal.h>

#define TIMER_VALUE 39 //to generate pulse of 10ms

unsigned int status;

SIGNAL(SIG_OVERFLOW1)
{

PORTA^=0xff;
TCNT1H = 0xf8;
TCNT1L = 0x5e; //load the timer count
}

void timer_init(void)
{

// set up counter1
SREG |= 0x80;
TCNT1H = 0xf8;
TCNT1L = 0x5e;
OCR1AH = 0x02;
OCR1AL = 0x00;
TCCR1A = 0x00;
TCCR1B = 0x04; //load prescaler to run counter at clk/256

TIMSK = 0x82; // enable tcnt1 and tcnt0 in free running mode

}

int main()
{
DDRA=0xff; //set PORT A as output port
PORTA=0xaa;

timer_init(); //enable all timers
for(;
{

}
return 0;
}


None of these are working, so tell me how to fix the bug........