]>
cloudbase.mooo.com Git - irmp.git/blob - main.c
f28cce9292ac5dac717f05087a586811c05d310b
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * main.c - demo main module to test irmp decoder
4 * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de
6 * $Id: main.c,v 1.8 2010/08/30 15:45:27 fm Exp $
10 * Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *---------------------------------------------------------------------------------------------------------------------------------------------------
19 /*---------------------------------------------------------------------------------------------------------------------------------------------------
20 * uncomment this for codevision compiler:
21 *---------------------------------------------------------------------------------------------------------------------------------------------------
23 // #define CODEVISION // to use Codevision Compiler instead of gcc
28 #define uint8_t unsigned char
29 #define uint16_t unsigned int
30 #define F_CPU 8000000 // change for Codevision here, if you use WinAVR, use Project -> Configuration Options instead
32 // register values from datasheet for ATMega88
46 #include <util/delay.h>
47 #include <avr/pgmspace.h>
48 #include <avr/interrupt.h>
50 #include "irmpconfig.h"
64 OCR1AH
= (( F_CPU
/ F_INTERRUPTS
) >> 8 ) & 0xFF ; // compare value: 1/10000 of CPU frequency (upper byte)
65 OCR1AL
= (( F_CPU
/ F_INTERRUPTS
) - 1 ) & 0xFF ; // compare value: 1/10000 of CPU frequency (lower byte)
67 OCR1A
= ( F_CPU
/ F_INTERRUPTS
) - 1 ; // compare value: 1/10000 of CPU frequency
69 TCCR1B
= ( 1 << WGM12
) | ( 1 << CS10
); // switch CTC Mode on, set prescaler to 1
71 #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega64__) || defined (__AVR_ATmega162__)
72 TIMSK
= 1 << OCIE1A
; // OCIE1A: Interrupt by timer compare
74 TIMSK1
= 1 << OCIE1A
; // OCIE1A: Interrupt by timer compare
78 /*---------------------------------------------------------------------------------------------------------------------------------------------------
79 * timer 1 compare handler, called every 1/10000 sec
80 *---------------------------------------------------------------------------------------------------------------------------------------------------
82 // Timer 1 output compare A interrupt service routine
84 interrupt
[ TIM1_COMPA
] void timer1_compa_isr ( void )
86 ISR ( TIMER1_COMPA_vect
)
89 ( void ) irmp_ISR (); // call irmp ISR
90 // call other timer interrupt routines...
93 /*---------------------------------------------------------------------------------------------------------------------------------------------------
95 *---------------------------------------------------------------------------------------------------------------------------------------------------
98 // This is the main routine if you use Codevision C Compiler
105 // crystal oscillator division factor: 1
108 #ifdef _OPTIMIZE_SIZE_
111 static uint8_t * Proto
[]={ "SIRCS" , "NEC" , "SAMSUNG" , "MATSUSH" , "KASEIKYO" , "RECS80" , "RC5(x)" , "DENON" , "RC6" , "SAMSG32" , "APPLE" , "RECS80X" , "NUBERT" , "B&O" , "GRUNDIG" , "NOKIA" , "SIEMENS" , "FDC" , "RCCAR" , "JVC" , "RC6A" };
113 #if IRMP_LOGGING == 0
114 // USART initialization has to be done here if Logging is off
115 // Communication Parameters: 8 Data, 1 Stop, No Parity
116 // USART Receiver: Off
117 // USART Transmitter: On
118 // USART0 Mode: Asynchronous
119 // USART Baud Rate: 9600
120 #define BAUDRATE 9600L
124 UBRR0H
= (( F_CPU
+ BAUDRATE
* 8 )/( BAUDRATE
* 16 )- 1 ) >> 8 ; // store baudrate (upper byte)
125 UBRR0L
= (( F_CPU
+ BAUDRATE
* 8 )/( BAUDRATE
* 16 )- 1 ) & 0xFF ;
128 irmp_init (); // initialize rc5
130 printf ( "IRMP V1.0 \n " );
131 #if IRMP_LOGGING == 1
132 printf ( "Logging Mode \n " );
135 timer_init (); // initialize timer
136 #asm( "sei" ); // enable interrupts
140 if ( irmp_get_data (& irmp_data
))
142 // ir signal decoded, do something here...
143 // irmp_data.protocol is the protocol, see irmp.h
144 // irmp_data.address is the address/manufacturer code of ir sender
145 // irmp_data.command is the command code
146 #if IRMP_LOGGING != 1
147 printf ( "Code: %s \n " , Proto
[ irmp_data
. protocol
- 1 ]);
148 printf ( "Address: 0x%.2X \n " , irmp_data
. address
);
149 printf ( "Command: 0x%.2X \n\n " , irmp_data
. command
);
157 // This is the main routine if you use GCC Compiler
163 irmp_init (); // initialize rc5
164 timer_init (); // initialize timer
165 sei (); // enable interrupts
169 if ( irmp_get_data (& irmp_data
))
171 // ir signal decoded, do something here...
172 // irmp_data.protocol is the protocol, see irmp.h
173 // irmp_data.address is the address/manufacturer code of ir sender
174 // irmp_data.command is the command code
179 #endif // CODEVISION / gcc