]> cloudbase.mooo.com Git - irmp.git/blob - irsndmain.c
Version 1.6.1: changed interfaces of irmp_ISR(), irsnd_send_data(), changed debug...
[irmp.git] / irsndmain.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irsndmain.c - demo main module to test irmp decoder
3 *
4 * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de
5 *
6 * ATMEGA88 @ 8 MHz
7 *
8 * Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *---------------------------------------------------------------------------------------------------------------------------------------------------
15 */
16
17 /*---------------------------------------------------------------------------------------------------------------------------------------------------
18 * uncomment this for codevision compiler:
19 *---------------------------------------------------------------------------------------------------------------------------------------------------
20 */
21 // #define CODEVISION // to use Codevision Compiler instead of gcc
22
23 #ifdef CODEVISION
24 #include <mega88.h>
25 #include <stdio.h>
26 #define uint8_t unsigned char
27 #define uint16_t unsigned int
28 #define F_CPU 8000000 // change for Codevision here, if you use WinAVR, use Project -> Configuration Options instead
29
30 // register values from datasheet for ATMega88
31 #define OCIE1A 1
32 #define WGM12 3
33 #define CS10 0
34 #define UDRE0 5
35 #define TXEN0 3
36
37 #include "irmp.h"
38 #include "isnd.h"
39 #include "irmp.c"
40 #include "isnd.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 "irsndconfig.h"
51 #include "irsnd.h"
52
53 #endif // CODEVISION
54
55 #ifndef F_CPU
56 #error F_CPU unkown
57 #endif
58
59 void
60 timer_init (void)
61 {
62 #ifdef CODEVISION
63 OCR1AH = ((F_CPU / F_INTERRUPTS) >> 8) & 0xFF; // compare value: 1/10000 of CPU frequency (upper byte)
64 OCR1AL = ((F_CPU / F_INTERRUPTS) - 1) & 0xFF; // compare value: 1/10000 of CPU frequency (lower byte)
65 #else // gcc
66 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/10000 of CPU frequency
67 #endif // CODEVISION
68 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
69
70 #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega64__) || defined (__AVR_ATmega162__)
71 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare (use TIMSK for ATMEGA162)
72 #else
73 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare (use TIMSK for ATMEGA162)
74 #endif // __AVR...
75 }
76
77 /*---------------------------------------------------------------------------------------------------------------------------------------------------
78 * timer 1 compare handler, called every 1/10000 sec
79 *---------------------------------------------------------------------------------------------------------------------------------------------------
80 */
81 // Timer 1 output compare A interrupt service routine
82 #ifdef CODEVISION
83 interrupt [TIM1_COMPA] void timer1_compa_isr(void)
84 #else // CODEVISION
85 ISR(TIMER1_COMPA_vect)
86 #endif // CODEVISION
87 {
88 (void) irsnd_ISR(); // call irsnd ISR
89 // call other timer interrupt routines...
90 }
91
92 /*---------------------------------------------------------------------------------------------------------------------------------------------------
93 * MAIN: main routine
94 *---------------------------------------------------------------------------------------------------------------------------------------------------
95 */
96 #ifdef CODEVISION
97 // This is the main routine if you use Codevision C Compiler
98 void
99 main (void)
100 {
101 IRMP_DATA irmp_data;
102
103 #pragma optsize-
104 // crystal oscillator division factor: 1
105 CLKPR=0x80;
106 CLKPR=0x00;
107 #ifdef _OPTIMIZE_SIZE_
108 #pragma optsize+
109 #endif
110
111 irsnd_init(); // initialize irsnd
112 timer_init(); // initialize timer
113 #asm("sei"); // enable interrupts
114
115 for (;;)
116 {
117 irmp_data.protocol = IRMP_NEC_PROTOCOL;
118 irmp_data.address = 0x00FF;
119 irmp_data.command = 0x0001;
120 irmp_data.flags = 0;
121
122 irsnd_send_data (&irmp_data);
123 _delay_ms (1000);
124 }
125 }
126
127 #else // gcc
128
129 // This is the main routine if you use GCC Compiler
130 int
131 main (void)
132 {
133 IRMP_DATA irmp_data;
134
135 irsnd_init(); // initialize irsnd
136 timer_init(); // initialize timer
137 sei (); // enable interrupts
138
139 for (;;)
140 {
141 irmp_data.protocol = IRMP_NEC_PROTOCOL;
142 irmp_data.address = 0x00FF;
143 irmp_data.command = 0x0001;
144 irmp_data.flags = 0;
145
146 irsnd_send_data (&irmp_data, TRUE);
147 _delay_ms (1000);
148 }
149 }
150
151 #endif // CODEVISION / gcc