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