]>
cloudbase.mooo.com Git - irmp.git/blob - main.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * main.c - demo main module to test irmp decoder
4 * Copyright (c) 2009-2013 Frank Meyer - frank(at)fli4l.de
6 * $Id: main.c,v 1.17 2013/01/17 07:33:14 fm Exp $
8 * This demo module is runnable on AVRs and LM4F120 Launchpad (ARM Cortex M4)
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
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 *---------------------------------------------------------------------------------------------------------------------------------------------------
26 /*---------------------------------------------------------------------------------------------------------------------------------------------------
28 *---------------------------------------------------------------------------------------------------------------------------------------------------
30 #if defined (ATMEL_AVR)
35 #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:
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
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
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
51 TIMSK1
= 1 << OCIE1A
; // OCIE1A: Interrupt by timer compare
53 TIMSK
= 1 << OCIE1A
; // OCIE1A: Interrupt by timer compare
57 #ifdef TIM1_COMPA_vect // ATtiny84
58 #define COMPA_VECT TIM1_COMPA_vect
60 #define COMPA_VECT TIMER1_COMPA_vect // ATmega
63 ISR(COMPA_VECT
) // Timer1 output compare A interrupt service routine, called every 1/15000 sec
65 (void) irmp_ISR(); // call irmp ISR
66 // call other timer interrupt routines...
74 irmp_init(); // initialize irmp
75 timer1_init(); // initialize timer1
76 sei (); // enable interrupts
80 if (irmp_get_data (&irmp_data
))
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)
91 /*---------------------------------------------------------------------------------------------------------------------------------------------------
92 * LM4F120 Launchpad (ARM Cortex M4):
93 *---------------------------------------------------------------------------------------------------------------------------------------------------
95 #elif defined(STELLARIS_ARM_CORTEX_M4)
100 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1
);
101 TimerConfigure(TIMER1_BASE
, TIMER_CFG_32_BIT_PER
);
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 !
111 Timer1IntHandler(void) // Timer1 Interrupt Handler
113 (void) irmp_ISR(); // call irmp ISR
114 // call other timer interrupt routines...
123 ROM_FPUStackingEnable();
124 ROM_SysCtlClockSet(SYSCTL_SYSDIV_5
|SYSCTL_USE_PLL
|SYSCTL_XTAL_16MHZ
|SYSCTL_OSC_MAIN
);
126 irmp_init(); // initialize irmp
127 timer1_init(); // initialize timer1
128 sei (); // enable interrupts
132 if (irmp_get_data (&irmp_data
))
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)