Senzory 1.0
timer.h
Go to the documentation of this file.
1#ifndef TIMER_H
2# define TIMER_H
3
4/*
5 * Timer library for AVR-GCC.
6 * (c) 2019-2025 Tomas Fryza, MIT license
7 *
8 * Developed using PlatformIO and Atmel AVR platform.
9 * Tested on Arduino Uno board and ATmega328P, 16 MHz.
10 */
11
26
27
28// -- Includes ---------------------------------------------
29#include <avr/io.h>
30
31
32// -- Defines ----------------------------------------------
38#define tim1_stop() TCCR1B &= ~((1<<CS12) | (1<<CS11) | (1<<CS10));
39
41#define tim1_ovf_4ms() TCCR1B &= ~((1<<CS12) | (1<<CS11)); TCCR1B |= (1<<CS10);
42
44#define tim1_ovf_33ms() TCCR1B &= ~((1<<CS12) | (1<<CS10)); TCCR1B |= (1<<CS11);
45
47#define tim1_ovf_262ms() TCCR1B &= ~(1<<CS12); TCCR1B |= (1<<CS11) | (1<<CS10);
48
50#define tim1_ovf_1sec() TCCR1B &= ~((1<<CS11) | (1<<CS10)); TCCR1B |= (1<<CS12);
51
53#define tim1_ovf_4sec() TCCR1B &= ~(1<<CS11); TCCR1B |= (1<<CS12) | (1<<CS10);
54
56#define tim1_ovf_enable() TIMSK1 |= (1<<TOIE1);
57
59#define tim1_ovf_disable() TIMSK1 &= ~(1<<TOIE1);
60
61
67#define tim0_stop() TCCR0B &= ~((1<<CS02) | (1<<CS01) | (1<<CS00));
68
70#define tim0_ovf_16us() TCCR0B &= ~((1<<CS02) | (1<<CS01)); TCCR0B |= (1<<CS00);
71
73#define tim0_ovf_128us() TCCR0B &= ~((1<<CS02) | (1<<CS00)); TCCR0B |= (1<<CS01);
74
76#define tim0_ovf_1ms() TCCR0B &= ~(1<<CS02); TCCR0B |= (1<<CS01) | (1<<CS00);
77
79#define tim0_ovf_4ms() TCCR0B &= ~((1<<CS01) | (1<<CS00)); TCCR0B |= (1<<CS02);
80
82#define tim0_ovf_16ms() TCCR0B &= ~(1<<CS01); TCCR0B |= (1<<CS02) | (1<<CS00);
83
85#define tim0_ovf_enable() TIMSK0 |= (1<<TOIE0);
86
88#define tim0_ovf_disable() TIMSK0 &= ~(1<<TOIE0);
89
90
96#define tim2_stop() TCCR2B &= ~((1<<CS22) | (1<<CS21) | (1<<CS20));
97
99#define tim2_ovf_16us() TCCR2B &= ~((1<<CS22) | (1<<CS21)); TCCR2B |= (1<<CS20);
100
102#define tim2_ovf_128us() TCCR2B &= ~((1<<CS22) | (1<<CS20)); TCCR2B |= (1<<CS21);
103
105#define tim2_ovf_512us() TCCR2B &= ~(1<<CS22); TCCR2B |= (1<<CS21) | (1<<CS20);
106
108#define tim2_ovf_1ms() TCCR2B &= ~((1<<CS21) | (1<<CS20)); TCCR2B |= (1<<CS22);
109
111#define tim2_ovf_2ms() TCCR2B &= ~(1<<CS21); TCCR2B |= (1<<CS22) | (1<<CS20);
112
114#define tim2_ovf_4ms() TCCR2B &= ~(1<<CS20); TCCR2B |= (1<<CS22) | (1<<CS21);
115
117#define tim2_ovf_16ms() TCCR2B = (1<<CS22) | (1<<CS21)| (1<<CS20);
118
120#define tim2_ovf_enable() TIMSK2 |= (1<<TOIE2);
121
123#define tim2_ovf_disable() TIMSK2 &= ~(1<<TOIE2);
124
125
127
128#endif