This repository has been archived on 2025-01-09. You can view files and clone it, but cannot push or open issues or pull requests.
pig-feeder/lib/utils/Timer.cpp

32 lines
910 B
C++
Raw 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.

//
// Created by User on 018 18.05.20.
//
#include "Timer.h"
void Timer1::setup(TimerPrescaler prescaler, uint16_t OCR) {
TCCR1B |= (1 << WGM12); //режим сброса по свпадению
switch (prescaler) {
case PRESCALER_NO:
TCCR1B |= (1 << CS10);
break;
case PRESCALER_8:
TCCR1B |= (1 << CS11);
break;
case PRESCALER_64:
TCCR1B |= (1 << CS10) | (1 << CS10);
break;
case PRESCALER_256:
TCCR1B |= (1 << CS12);
break;
case PRESCALER_1024:
TCCR1B |= (1 << CS12) | (1 << CS10);
break;
}
TIMSK1 |= (1 << OCIE1A); //устанавливаем бит разрешения прерывания 1ого счетчика по совпадению с OCR1A(H и L)
OCR1AH = (OCR & 0xFF00) >> 8;
OCR1AL = (OCR & 0x00FF);
}