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