I'm doing register level programming in arduino.The goal is to write my own delay logic using timers.Here is the code
#include<avr/io.h>
int main()
{
DDRB=(1<<PORTB5);
TCCR1B=(1<<CS12);
while(1)
{
if(TCNT1>=31250)
{
PORTB^=(1<<PORTB5);
TCNT1=0;
}
}
return 0;
}
The above program is for arduino to introduce delay without using delay function and its working alright.But have a look at the code below.
#include<avr/io.h>
void setup()
{
DDRB=(1<<PORTB5);
TCCR1B=(1<<CS12);
}
void loop()
{
if(TCNT1>=31250)
{
PORTB^=(1<<PORTB5);
TCNT1=0;
}
}
When I write it this way,the program is getting compiled but there is no blinking in arduino. What might be the problem?