-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
46 lines (33 loc) · 774 Bytes
/
timer.c
File metadata and controls
46 lines (33 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* timer.c
*
* Created: 2/12/2022 1:40:57 AM
* Author: Ali
*/
#include <avr/io.h>
void timer_delay_m(unsigned int millisec)
{
TCCR0A = (1<<WGM01); /* CTC */
TCCR0B = (1<<CS01)|(1<<CS00); /* clock/1024 */
OCR0A = 249; /*Count for 1 millisecond*/
for (int i = 0; i < millisec ; i++)
{
while((TIFR0 & (1<<OCF0A))==0);
TIFR0 = (1<<OCF0A);
}
TCCR0A = 0;
TCCR0B = 0;
}
void timer_delay_u(unsigned int microsec)
{
TCCR0A = (1<<WGM01); /* CTC */
TCCR0B = (1<<CS00); /* clock/1 */
OCR0A = 15; /*Count for 1 microsecond*/
for (int i = 0; i < microsec ; i++)
{
while((TIFR0 & (1<<OCF0A))==0);
TIFR0 = (1<<OCF0A);
}
TCCR0A = 0;
TCCR0B = 0;
}