Society of Robots - Robot Forum
Software => Software => Topic started by: harisankarsa on April 15, 2008, 10:54:34 AM
-
Can anyone pls give me sample codes for using functions in timer.h...i have to use timer for calculating time in sec between two interrupts...i also need to do a loop after 5 mins...pls give me some valid codes..its urgent...
-
is there any timer.h in the avr library??
are u talking abt delay.h?
-
there IS a timer.h.
-
there is also a timerx8.h if your running at 8mhz
Check out the timer tutorial under programming here on the site. There is sample code in there.
-
I actually need to know how to use the real time clock on the atmega8 chip...pls give me some sample code...its for my final yr project..
-
this is a sample code which i have written for u which will make the led blink
this is for atmega16 so just change the port and pin no in the ddr... line and ull know how timers will work
# include<avr/io.h>
int main(void) // for 8 mhz internal oscillator 1 sec gap//
{
DDRC|=_BV(0);//set port c pin 0 as output
TCCR1B|=(1<<CS12);//start 16 bit timer at prescaler of 256 where 1 sec=31250 clock ticks
while(1)
{
if(TCNT1>=31250)
{
PORTC^=(1<<0);//toggle the pin on and off
TCNT1=0;//make tcnt1 as 0 for restarting the counter
}
}
return(1);
}
-
The timer.h file explains exactly how to use it.
Just include the proper files in the makefile and in the header, and just call the functions as described in the AVRlib documentation.
For example, if I wanted to delay 1ms, I'd just call this one line:
delay_ms(1000);
-
i think that is delay.h header file or does it vary from versions to versions