]> cloudbase.mooo.com Git - irmp.git/blob - main.c
version 2.0.0-pre3: changed handling of double width pulses/pauses in manchester...
[irmp.git] / main.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * main.c - demo main module to test irmp decoder
3 *
4 * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: main.c,v 1.9 2011/04/11 12:54:25 fm Exp $
7 *
8 * ATMEGA88 @ 8 MHz
9 *
10 * Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9
11 *
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 *---------------------------------------------------------------------------------------------------------------------------------------------------
17 */
18
19 /*---------------------------------------------------------------------------------------------------------------------------------------------------
20 * uncomment this for codevision compiler:
21 *---------------------------------------------------------------------------------------------------------------------------------------------------
22 */
23 // #define CODEVISION // to use Codevision Compiler instead of gcc
24
25 #ifdef CODEVISION
26 #include <mega88.h>
27 #include <stdio.h>
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
31
32 // register values from datasheet for ATMega88
33 #define OCIE1A 1
34 #define WGM12 3
35 #define CS10 0
36 #define UDRE0 5
37 #define TXEN0 3
38
39 #include "irmp.h"
40 #include "irmp.c"
41
42 #else // gcc compiler
43
44 #include <inttypes.h>
45 #include <avr/io.h>
46 #include <util/delay.h>
47 #include <avr/pgmspace.h>
48 #include <avr/interrupt.h>
49 #include "irmp.h"
50 #include "irmpconfig.h"
51
52
53 #endif // CODEVISION
54
55
56 #ifndef F_CPU
57 #error F_CPU unkown
58 #endif
59
60 void
61 timer_init (void)
62 {
63 #ifdef CODEVISION
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)
66 #else // gcc
67 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/10000 of CPU frequency
68 #endif // CODEVISION
69 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
70
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
73 #else
74 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
75 #endif // __AVR...
76 }
77
78 /*---------------------------------------------------------------------------------------------------------------------------------------------------
79 * timer 1 compare handler, called every 1/10000 sec
80 *---------------------------------------------------------------------------------------------------------------------------------------------------
81 */
82 // Timer 1 output compare A interrupt service routine
83 #ifdef CODEVISION
84 interrupt [TIM1_COMPA] void timer1_compa_isr(void)
85 #else // CODEVISION
86 ISR(TIMER1_COMPA_vect)
87 #endif // CODEVISION
88 {
89 (void) irmp_ISR(); // call irmp ISR
90 // call other timer interrupt routines...
91 }
92
93 /*---------------------------------------------------------------------------------------------------------------------------------------------------
94 * MAIN: main routine
95 *---------------------------------------------------------------------------------------------------------------------------------------------------
96 */
97 #ifdef CODEVISION
98 // This is the main routine if you use Codevision C Compiler
99 void
100 main (void)
101 {
102 IRMP_DATA irmp_data;
103
104 #pragma optsize-
105 // crystal oscillator division factor: 1
106 CLKPR=0x80;
107 CLKPR=0x00;
108 #ifdef _OPTIMIZE_SIZE_
109 #pragma optsize+
110 #endif
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"};
112
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
121 UCSR0A=0x00;
122 UCSR0B=0x08;
123 UCSR0C=0x06;
124 UBRR0H = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) >> 8; // store baudrate (upper byte)
125 UBRR0L = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) & 0xFF;
126 #endif
127
128 irmp_init(); // initialize rc5
129
130 printf("IRMP V1.0\n");
131 #if IRMP_LOGGING == 1
132 printf("Logging Mode\n");
133 #endif
134
135 timer_init(); // initialize timer
136 #asm("sei"); // enable interrupts
137
138 for (;;)
139 {
140 if (irmp_get_data (&irmp_data))
141 {
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);
150 #endif
151 }
152 }
153 }
154
155 #else // gcc
156
157 // This is the main routine if you use GCC Compiler
158 int
159 main (void)
160 {
161 IRMP_DATA irmp_data;
162
163 irmp_init(); // initialize rc5
164 timer_init(); // initialize timer
165 sei (); // enable interrupts
166
167 for (;;)
168 {
169 if (irmp_get_data (&irmp_data))
170 {
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
175 }
176 }
177 }
178
179 #endif // CODEVISION / gcc