Create library for software timers and enable it
This commit is contained in:
3
main.c
3
main.c
@@ -1,6 +1,6 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include "ptimer.h"
|
||||
#include "i2c.h"
|
||||
#include "rtc.h"
|
||||
#include "led.h"
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
ptimer_init();
|
||||
i2c_init(I2C_BITRATE);
|
||||
rtc_int0_init();
|
||||
led_init();
|
||||
|
||||
23
ptimer.c
Normal file
23
ptimer.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include "ptimer.h"
|
||||
|
||||
volatile uint16_t timers[TIMERS_COUNT];
|
||||
|
||||
void ptimer_init(void)
|
||||
{
|
||||
for(uint8_t i=0; i<TIMERS_COUNT; ++i) timers[i] = 0;
|
||||
|
||||
TCCR2 |= (1<<WGM21); // CTC Mode
|
||||
TCCR2 |= (1<<CS22) | (1<<CS21) | (1<<CS20); // Prescaler 1024
|
||||
OCR2 = 78; // ~100Hz
|
||||
TIMSK |= (1<<OCIE2); // Enable CTC interruptions
|
||||
}
|
||||
|
||||
ISR(TIMER2_COMP_vect)
|
||||
{
|
||||
for(uint8_t i=0; i<TIMERS_COUNT; ++i)
|
||||
{
|
||||
if(timers[i]) --timers[i];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user