]> cloudbase.mooo.com Git - irmp.git/blob - main.c
Version 2.6.0: added SAMSUNG48 protocol (in IRSND).
[irmp.git] / main.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * main.c - demo main module to test irmp decoder
3 *
4 * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: main.c,v 1.18 2014/07/01 07:50:33 fm Exp $
7 *
8 * This demo module is runnable on AVRs and LM4F120 Launchpad (ARM Cortex M4)
9 *
10 * ATMEGA88 @ 8 MHz internal RC Osc with BODLEVEL 4.3V: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9
11 * ATMEGA88 @ 8 MHz external Crystal Osc with BODLEVEL 4.3V: lfuse: 0xFF hfuse: 0xDC efuse: 0xF9
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *---------------------------------------------------------------------------------------------------------------------------------------------------
18 */
19
20 #include "irmp.h"
21
22 #ifndef F_CPU
23 #error F_CPU unkown
24 #endif
25
26 /*---------------------------------------------------------------------------------------------------------------------------------------------------
27 * ATMEL AVR part:
28 *---------------------------------------------------------------------------------------------------------------------------------------------------
29 */
30 #if defined (ATMEL_AVR)
31
32 void
33 timer1_init (void)
34 {
35 #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:
36
37 #if F_CPU >= 16000000L
38 OCR1C = (F_CPU / F_INTERRUPTS / 8) - 1; // compare value: 1/15000 of CPU frequency, presc = 8
39 TCCR1 = (1 << CTC1) | (1 << CS12); // switch CTC Mode on, set prescaler to 8
40 #else
41 OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4
42 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4
43 #endif
44
45 #else // ATmegaXX:
46 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency
47 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
48 #endif
49
50 #ifdef TIMSK1
51 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
52 #else
53 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
54 #endif
55 }
56
57 #ifdef TIM1_COMPA_vect // ATtiny84
58 #define COMPA_VECT TIM1_COMPA_vect
59 #else
60 #define COMPA_VECT TIMER1_COMPA_vect // ATmega
61 #endif
62
63 ISR(COMPA_VECT) // Timer1 output compare A interrupt service routine, called every 1/15000 sec
64 {
65 (void) irmp_ISR(); // call irmp ISR
66 // call other timer interrupt routines...
67 }
68
69 int
70 main (void)
71 {
72 IRMP_DATA irmp_data;
73
74 irmp_init(); // initialize irmp
75 timer1_init(); // initialize timer1
76 sei (); // enable interrupts
77
78 for (;;)
79 {
80 if (irmp_get_data (&irmp_data))
81 {
82 // ir signal decoded, do something here...
83 // irmp_data.protocol is the protocol, see irmp.h
84 // irmp_data.address is the address/manufacturer code of ir sender
85 // irmp_data.command is the command code
86 // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
87 }
88 }
89 }
90
91 /*---------------------------------------------------------------------------------------------------------------------------------------------------
92 * LM4F120 Launchpad (ARM Cortex M4):
93 *---------------------------------------------------------------------------------------------------------------------------------------------------
94 */
95 #elif defined(STELLARIS_ARM_CORTEX_M4)
96
97 void
98 timer1_init (void)
99 {
100 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
101 TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER);
102
103 TimerLoadSet(TIMER1_BASE, TIMER_A, (F_CPU / F_INTERRUPTS) -1);
104 IntEnable(INT_TIMER1A);
105 TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
106 TimerEnable(TIMER1_BASE, TIMER_A);
107 // Important: Timer1IntHandler has to be configured in startup_ccs.c !
108 }
109
110 void
111 Timer1IntHandler(void) // Timer1 Interrupt Handler
112 {
113 (void) irmp_ISR(); // call irmp ISR
114 // call other timer interrupt routines...
115 }
116
117 int
118 main (void)
119 {
120 IRMP_DATA irmp_data;
121
122 ROM_FPUEnable();
123 ROM_FPUStackingEnable();
124 ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
125
126 irmp_init(); // initialize irmp
127 timer1_init(); // initialize timer1
128 sei (); // enable interrupts
129
130 for (;;)
131 {
132 if (irmp_get_data (&irmp_data))
133 {
134 // ir signal decoded, do something here...
135 // irmp_data.protocol is the protocol, see irmp.h
136 // irmp_data.address is the address/manufacturer code of ir sender
137 // irmp_data.command is the command code
138 // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
139 }
140 }
141 }
142
143 /*---------------------------------------------------------------------------------------------------------------------------------------------------
144 * PIC18F4520 with XC8 compiler:
145 *---------------------------------------------------------------------------------------------------------------------------------------------------
146 */
147 #elif defined (__XC8)
148
149 #define _XTAL_FREQ 32000000UL // 32MHz clock
150 #define FOSC _XTAL_FREQ
151 #define FCY FOSC / 4UL // --> 8MHz
152
153 #define BAUDRATE 19200UL
154 #define BRG (( FCY 16 BAUDRATE ) -1UL)
155
156 #include <stdio.h>
157 #include <stdlib.h>
158
159 int
160 main (void)
161 {
162 IRMP_DATA irmp_data;
163
164 irmp_init(); // initialize irmp
165
166 // infinite loop, interrupts will blink PORTD pins and handle UART communications.
167 while (1)
168 {
169 LATBbits.LATB0 = ~LATBbits.LATB0;
170
171 if (irmp_get_data (&irmp_data))
172 {
173 // ir signal decoded, do something here...
174 // irmp_data.protocol is the protocol, see irmp.h
175 // irmp_data.address is the address/manufacturer code of ir sender
176 // irmp_data.command is the command code
177 // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
178 printf("proto %d addr %d cmd %d\n", irmp_data.protocol, irmp_data.address, irmp_data.command );
179 }
180 }
181 }
182
183 void interrupt high_priority high_isr(void)
184 {
185 if (TMR2IF)
186 {
187 TMR2IF = 0; // clear Timer 0 interrupt flag
188 irmp_ISR();
189 }
190 }
191
192 #endif