]> cloudbase.mooo.com Git - irmp.git/blob - irsndmain.c
Corrected Timer for ATTiny85
[irmp.git] / irsndmain.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irsndmain.c - demo main module to test irmp decoder
3 *
4 * Copyright (c) 2010-2011 Frank Meyer - frank(at)fli4l.de
5 *
6 * ATMEGA88 @ 8 MHz
7 *
8 * Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *---------------------------------------------------------------------------------------------------------------------------------------------------
15 */
16
17 #include <inttypes.h>
18 #include <avr/io.h>
19 #include <util/delay.h>
20 #include <avr/pgmspace.h>
21 #include <avr/interrupt.h>
22 #include "irmp.h"
23 #include "irsndconfig.h"
24 #include "irsnd.h"
25
26 #ifndef F_CPU
27 #error F_CPU unkown
28 #endif
29
30 void
31 timer1_init (void)
32 {
33 #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:
34 OCR1A = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4
35 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4
36 #else // ATmegaXX:
37 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency
38 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
39 #endif
40
41 #ifdef TIMSK1
42 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
43 #else
44 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
45 #endif
46 }
47
48 /*---------------------------------------------------------------------------------------------------------------------------------------------------
49 * timer 1 compare handler, called every 1/10000 sec
50 *---------------------------------------------------------------------------------------------------------------------------------------------------
51 */
52 ISR(TIMER1_COMPA_vect)
53 {
54 (void) irsnd_ISR(); // call irsnd ISR
55 // call other timer interrupt routines here...
56 }
57
58 /*---------------------------------------------------------------------------------------------------------------------------------------------------
59 * MAIN: main routine
60 *---------------------------------------------------------------------------------------------------------------------------------------------------
61 */
62 int
63 main (void)
64 {
65 IRMP_DATA irmp_data;
66
67 irsnd_init(); // initialize irsnd
68 timer1_init(); // initialize timer
69 sei (); // enable interrupts
70
71 for (;;)
72 {
73 irmp_data.protocol = IRMP_NEC_PROTOCOL;
74 irmp_data.address = 0x00FF;
75 irmp_data.command = 0x0001;
76 irmp_data.flags = 0;
77
78 irsnd_send_data (&irmp_data, TRUE);
79 _delay_ms (1000);
80 }
81 }