blob: 4e666daeba5091311162df6e2431dd358672f76d (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*---------------------------------------------------------------------------------------------------------------------------------------------------
* main.c - demo main module to test irmp decoder
*
* Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de
*
* $Id: main.c,v 1.12 2012/02/13 10:59:07 fm Exp $
*
* ATMEGA88 @ 8 MHz
*
* Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "irmpconfig.h"
#include "irmp.h"
#ifndef F_CPU
#error F_CPU unkown
#endif
void
timer1_init (void)
{
#if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:
#if F_CPU >= 16000000L
OCR1C = (F_CPU / F_INTERRUPTS / 8) - 1; // compare value: 1/15000 of CPU frequency, presc = 8
TCCR1 = (1 << CTC1) | (1 << CS12); // switch CTC Mode on, set prescaler to 8
#else
OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4
TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4
#endif
#else // ATmegaXX:
OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency
TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
#endif
#ifdef TIMSK1
TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
#else
TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
#endif
}
/*---------------------------------------------------------------------------------------------------------------------------------------------------
* Timer 1 output compare A interrupt service routine, called every 1/15000 sec
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
#ifdef TIM1_COMPA_vect // ATtiny84
ISR(TIM1_COMPA_vect)
#else
ISR(TIMER1_COMPA_vect)
#endif
{
(void) irmp_ISR(); // call irmp ISR
// call other timer interrupt routines...
}
int
main (void)
{
IRMP_DATA irmp_data;
irmp_init(); // initialize irmp
timer1_init(); // initialize timer 1
sei (); // enable interrupts
for (;;)
{
if (irmp_get_data (&irmp_data))
{
// ir signal decoded, do something here...
// irmp_data.protocol is the protocol, see irmp.h
// irmp_data.address is the address/manufacturer code of ir sender
// irmp_data.command is the command code
// irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
}
}
}
|