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