]> cloudbase.mooo.com Git - irmp.git/blob - irsndmain.c
Version 2.2.3: added support for ATtiny167
[irmp.git] / irsndmain.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irsndmain.c - demo main module to test irsnd encoder
3 *
4 * Copyright (c) 2010-2012 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 #include "irsnd.h"
17
18 #ifndef F_CPU
19 # error F_CPU unkown
20 #endif
21
22 void
23 timer1_init (void)
24 {
25 #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:
26 OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4
27 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4
28 #else // ATmegaXX:
29 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency
30 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
31 #endif
32
33 #ifdef TIMSK1
34 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
35 #else
36 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
37 #endif
38 }
39
40 /*---------------------------------------------------------------------------------------------------------------------------------------------------
41 * timer 1 compare handler, called every 1/10000 sec
42 *---------------------------------------------------------------------------------------------------------------------------------------------------
43 */
44 ISR(TIMER1_COMPA_vect)
45 {
46 (void) irsnd_ISR(); // call irsnd ISR
47 // call other timer interrupt routines here...
48 }
49
50 /*---------------------------------------------------------------------------------------------------------------------------------------------------
51 * MAIN: main routine
52 *---------------------------------------------------------------------------------------------------------------------------------------------------
53 */
54 int
55 main (void)
56 {
57 IRMP_DATA irmp_data;
58
59 irsnd_init(); // initialize irsnd
60 timer1_init(); // initialize timer
61 sei (); // enable interrupts
62
63 for (;;)
64 {
65 irmp_data.protocol = IRMP_NEC_PROTOCOL;
66 irmp_data.address = 0x00FF;
67 irmp_data.command = 0x0001;
68 irmp_data.flags = 0;
69
70 irsnd_send_data (&irmp_data, TRUE);
71 _delay_ms (1000);
72 }
73 }