Hi,
I have written the code for led blinking, using timer0 of ATmega2560 on AtmelStudio7. When I run it on simulator, the status of led(s) changes without timer reaching the set value. Can someone assist me with this..? Thanks in advance..
Here is the code:
I have written the code for led blinking, using timer0 of ATmega2560 on AtmelStudio7. When I run it on simulator, the status of led(s) changes without timer reaching the set value. Can someone assist me with this..? Thanks in advance..
Here is the code:
Code:
#include <avr/io.h>
void delaynew ();
int main(void)
{
DDRB = 0xFF; //PortB is set as o/p
while (1)
{
PORTB = 0xAA;
delaynew();
PORTB = 0x55;
delaynew();
}
}
void delaynew (void)
{
TCCR0A =0xC2; //Clear timer on compare match mode is set
//TCNT0 = 0x00; //Initialized the counter
OCR0A = 0x70; //Set the delay to 50 a/c to decimal
TCCR0B = 0x01; //set the clock with no prescale
while ((TIFR0 & 0b00000011) == 0b00000011)
{
TCCR0B = 0x00;
TIFR0 = 0x03;
}
}