/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
* main.c - demo main module to test irmp decoder\r
*\r
- * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de\r
*\r
- * $Id: main.c,v 1.7 2010/06/22 08:33:21 fm Exp $\r
+ * $Id: main.c,v 1.9 2011/04/11 12:54:25 fm Exp $\r
*\r
* ATMEGA88 @ 8 MHz\r
*\r
*---------------------------------------------------------------------------------------------------------------------------------------------------\r
*/\r
\r
-/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
- * uncomment this for codevision compiler:\r
- *---------------------------------------------------------------------------------------------------------------------------------------------------\r
- */\r
-// #define CODEVISION // to use Codevision Compiler instead of gcc\r
- \r
-#ifdef CODEVISION \r
-#include <mega88.h>\r
-#include <stdio.h>\r
-#define uint8_t unsigned char\r
-#define uint16_t unsigned int\r
-#define F_CPU 8000000 // change for Codevision here, if you use WinAVR, use Project -> Configuration Options instead\r
-\r
-// register values from datasheet for ATMega88\r
-#define OCIE1A 1\r
-#define WGM12 3\r
-#define CS10 0\r
-#define UDRE0 5\r
-#define TXEN0 3\r
-\r
-#include "irmp.h"\r
-#include "irmp.c"\r
-\r
-#else // gcc compiler\r
-\r
#include <inttypes.h>\r
#include <avr/io.h>\r
#include <util/delay.h>\r
#include <avr/pgmspace.h>\r
#include <avr/interrupt.h>\r
-#include "irmp.h"\r
-#include "irmpconfig.h"\r
-\r
-\r
-#endif // CODEVISION\r
\r
+#include "irmpconfig.h"\r
+#include "irmp.h"\r
\r
#ifndef F_CPU\r
#error F_CPU unkown\r
#endif\r
\r
void\r
-timer_init (void)\r
+timer1_init (void)\r
{\r
-#ifdef CODEVISION\r
- OCR1AH = ((F_CPU / F_INTERRUPTS) >> 8) & 0xFF; // compare value: 1/10000 of CPU frequency (upper byte)\r
- OCR1AL = ((F_CPU / F_INTERRUPTS) - 1) & 0xFF; // compare value: 1/10000 of CPU frequency (lower byte)\r
-#else // gcc\r
- OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/10000 of CPU frequency\r
-#endif // CODEVISION\r
- TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1\r
+#if defined (__AVR_ATtiny85__) // ATtiny85:\r
+ OCR1A = (F_CPU / (2 * F_INTERRUPTS) / 2) - 1; // compare value: 1/28800 of CPU frequency, presc = 2\r
+ TCCR1 = (1 << CTC1) | (1 << CS11); // switch CTC Mode on, set prescaler to 2\r
+#else // ATmegaXX:\r
+ OCR1A = (F_CPU / (2 * F_INTERRUPTS)) - 1; // compare value: 1/28800 of CPU frequency\r
+ TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1\r
+#endif\r
\r
-#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega64__) || defined (__AVR_ATmega162__) \r
- TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
+#ifdef TIMSK1\r
+ TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
#else\r
- TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
-#endif // __AVR...\r
-}\r
-\r
-/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
- * timer 1 compare handler, called every 1/10000 sec\r
- *---------------------------------------------------------------------------------------------------------------------------------------------------\r
- */\r
-// Timer 1 output compare A interrupt service routine\r
-#ifdef CODEVISION\r
-interrupt [TIM1_COMPA] void timer1_compa_isr(void)\r
-#else // CODEVISION\r
-ISR(TIMER1_COMPA_vect)\r
-#endif // CODEVISION\r
-{\r
- (void) irmp_ISR(); // call irmp ISR\r
- // call other timer interrupt routines...\r
-}\r
-\r
-/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
- * MAIN: main routine\r
- *---------------------------------------------------------------------------------------------------------------------------------------------------\r
- */\r
-#ifdef CODEVISION\r
-// This is the main routine if you use Codevision C Compiler\r
-void\r
-main (void)\r
-{\r
- IRMP_DATA irmp_data;\r
-\r
- #pragma optsize-\r
- // crystal oscillator division factor: 1\r
- CLKPR=0x80;\r
- CLKPR=0x00;\r
- #ifdef _OPTIMIZE_SIZE_\r
- #pragma optsize+\r
- #endif\r
- static uint8_t *Proto[]={"SIRCS","NEC","SAMSUNG","MATSUSH","KASEIKYO","RECS80","RC5(x)","DENON","RC6","SAMSG32","APPLE"};\r
- #define IRMP_APPLE_ADDRESS 0x77E1 \r
-\r
-\r
- #if IRMP_LOGGING == 0\r
- // USART initialization has to be done here if Logging is off\r
- // Communication Parameters: 8 Data, 1 Stop, No Parity\r
- // USART Receiver: Off\r
- // USART Transmitter: On\r
- // USART0 Mode: Asynchronous\r
- // USART Baud Rate: 9600\r
- #define BAUDRATE 9600L\r
- UCSR0A=0x00;\r
- UCSR0B=0x08;\r
- UCSR0C=0x06;\r
- UBRR0H = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) >> 8; // store baudrate (upper byte)\r
- UBRR0L = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) & 0xFF; \r
- #endif\r
-\r
- irmp_init(); // initialize rc5\r
-\r
- printf("IRMP V1.0\n");\r
- #if IRMP_LOGGING == 1\r
- printf("Logging Mode\n");\r
- #endif\r
-\r
- timer_init(); // initialize timer\r
- #asm("sei"); // enable interrupts\r
-\r
- for (;;)\r
- {\r
- if (irmp_get_data (&irmp_data))\r
- {\r
- // ir signal decoded, do something here...\r
- // irmp_data.protocol is the protocol, see irmp.h\r
- // irmp_data.address is the address/manufacturer code of ir sender\r
- // irmp_data.command is the command code\r
- #if IRMP_LOGGING != 1\r
- if((irmp_data.protocol == IRMP_NEC_PROTOCOL) && (irmp_data.address == IRMP_APPLE_ADDRESS))\r
- printf("Code: Apple\n");\r
- else printf("Code: %s\n",Proto[irmp_data.protocol-1]);\r
- printf("Address: 0x%.2X\n",irmp_data.address);\r
- printf("Command: 0x%.2X\n\n",irmp_data.command);\r
- #endif\r
- }\r
- }\r
+ TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
+#endif\r
}\r
\r
-#else // gcc\r
-\r
-// This is the main routine if you use GCC Compiler\r
int\r
main (void)\r
{\r
- IRMP_DATA irmp_data;\r
+ IRMP_DATA irmp_data;\r
\r
- irmp_init(); // initialize rc5\r
- timer_init(); // initialize timer\r
- sei (); // enable interrupts\r
+ irmp_init(); // initialize irmp\r
+ timer1_init(); // initialize timer 1\r
+ sei (); // enable interrupts\r
\r
- for (;;)\r
- {\r
- if (irmp_get_data (&irmp_data))\r
+ for (;;)\r
{\r
- // ir signal decoded, do something here...\r
- // irmp_data.protocol is the protocol, see irmp.h\r
- // irmp_data.address is the address/manufacturer code of ir sender\r
- // irmp_data.command is the command code\r
+ if (irmp_get_data (&irmp_data))\r
+ {\r
+ // ir signal decoded, do something here...\r
+ // irmp_data.protocol is the protocol, see irmp.h\r
+ // irmp_data.address is the address/manufacturer code of ir sender\r
+ // irmp_data.command is the command code\r
+ // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)\r
+ }\r
}\r
- }\r
}\r
-\r
-#endif // CODEVISION / gcc\r