Modbus_1_Deva4ki/timer.c

28 lines
682 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <avr/io.h>
#include <avr/interrupt.h>
static unsigned long millis = 0;
void setup_timer()
{
// Включаем режим СТС
TCCR0A = (1 << WGM01);
// Устанавливаем счетчик с предделителем 64
TCCR0B = (1 << CS01) | (1 << CS00);
// Устанавливаем значение сравнения для 1 мс
OCR0A = 250;
// Разрешаем прерывание по совпадению
TIMSK0 = (1 << OCIE0A);
// Разрешаем все прерывания
sei();
}
unsigned long get_millis()
{
return millis;
}
ISR(TIMER0_COMPA_vect)
{
++millis;
}