]>
cloudbase.mooo.com Git - irmp.git/blob - main.c
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.6 2010/06/10 10:09:47 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" };
112 #define IRMP_APPLE_ADDRESS 0x77E1
115 #if IRMP_LOGGING == 0
116 // USART initialization has to be done here if Logging is off
117 // Communication Parameters: 8 Data, 1 Stop, No Parity
118 // USART Receiver: Off
119 // USART Transmitter: On
120 // USART0 Mode: Asynchronous
121 // USART Baud Rate: 9600
122 #define BAUDRATE 9600L
126 UBRR0H
= (( F_CPU
+ BAUDRATE
* 8 )/( BAUDRATE
* 16 )- 1 ) >> 8 ; // store baudrate (upper byte)
127 UBRR0L
= (( F_CPU
+ BAUDRATE
* 8 )/( BAUDRATE
* 16 )- 1 ) & 0xFF ;
130 irmp_init (); // initialize rc5
132 printf ( "IRMP V1.0 \n " );
133 #if IRMP_LOGGING == 1
134 printf ( "Logging Mode \n " );
137 timer_init (); // initialize timer
138 #asm( "sei" ); // enable interrupts
142 if ( irmp_get_data (& irmp_data
))
144 // ir signal decoded, do something here...
145 // irmp_data.protocol is the protocol, see irmp.h
146 // irmp_data.address is the address/manufacturer code of ir sender
147 // irmp_data.command is the command code
148 #if IRMP_LOGGING != 1
149 if (( irmp_data
. protocol
== IRMP_NEC_PROTOCOL
) && ( irmp_data
. address
== IRMP_APPLE_ADDRESS
))
150 printf ( "Code: Apple \n " );
151 else printf ( "Code: %s \n " , Proto
[ irmp_data
. protocol
- 1 ]);
152 printf ( "Address: 0x%.2X \n " , irmp_data
. address
);
153 printf ( "Command: 0x%.2X \n\n " , irmp_data
. command
);
161 // This is the main routine if you use GCC Compiler
167 irmp_init (); // initialize rc5
168 timer_init (); // initialize timer
169 sei (); // enable interrupts
173 if ( irmp_get_data (& irmp_data
))
175 // ir signal decoded, do something here...
176 // irmp_data.protocol is the protocol, see irmp.h
177 // irmp_data.address is the address/manufacturer code of ir sender
178 // irmp_data.command is the command code
183 #endif // CODEVISION / gcc