TIMER using AVR:
AVR have 3 types of Timer.
1) Timer 0= 8 bit
2) Timer1= 16 bit
3) Timer 2= 8 bit
Program: 1 sec delay using Timer 0:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
int i;
DDRD=0xFF;
TCCR0=0x01;
while(1)
{
for(i=0;i<5000;i++)
{
TCNT0=0x38;
while((TIFR&0x01)==0);
TIFR=0x01;
}
PORTD=~PORTD;
}
}
AVR have 3 types of Timer.
1) Timer 0= 8 bit
2) Timer1= 16 bit
3) Timer 2= 8 bit
Program: 1 sec delay using Timer 0:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
int i;
DDRD=0xFF;
TCCR0=0x01;
while(1)
{
for(i=0;i<5000;i++)
{
TCNT0=0x38;
while((TIFR&0x01)==0);
TIFR=0x01;
}
PORTD=~PORTD;
}
}
0 comments:
Post a Comment
if you have any doubt please let me know