X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/blobdiff_plain/6f75002072ad07fe60d9e57370d3980b5229f7f4..173b00a6f5d5c604471f9755d80c9181da15133c:/irsndmain.c diff --git a/irsndmain.c b/irsndmain.c index e5a03cb..6355635 100644 --- a/irsndmain.c +++ b/irsndmain.c @@ -1,11 +1,10 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- - * irsndmain.c - demo main module to test irmp decoder + * irsndmain.c - demo main module to test IRSND encoder on AVRs * - * Copyright (c) 2010 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2010-2015 Frank Meyer - frank(at)fli4l.de * - * ATMEGA88 @ 8 MHz - * - * Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9 + * ATMEGA88 @ 8 MHz internal RC Osc with BODLEVEL 4.3V: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9 + * ATMEGA88 @ 8 MHz external Crystal Osc with BODLEVEL 4.3V: lfuse: 0xFF hfuse: 0xDC efuse: 0xF9 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -13,139 +12,67 @@ * (at your option) any later version. *--------------------------------------------------------------------------------------------------------------------------------------------------- */ - -/*--------------------------------------------------------------------------------------------------------------------------------------------------- - * uncomment this for codevision compiler: - *--------------------------------------------------------------------------------------------------------------------------------------------------- - */ -// #define CODEVISION // to use Codevision Compiler instead of gcc - -#ifdef CODEVISION -#include -#include -#define uint8_t unsigned char -#define uint16_t unsigned int -#define F_CPU 8000000 // change for Codevision here, if you use WinAVR, use Project -> Configuration Options instead - -// register values from datasheet for ATMega88 -#define OCIE1A 1 -#define WGM12 3 -#define CS10 0 -#define UDRE0 5 -#define TXEN0 3 - -#include "irmp.h" -#include "isnd.h" -#include "irmp.c" -#include "isnd.c" - -#else // gcc compiler - -#include -#include -#include -#include -#include -#include "irmp.h" -#include "irsndconfig.h" #include "irsnd.h" -#endif // CODEVISION - #ifndef F_CPU -#error F_CPU unkown +# error F_CPU unknown #endif void -timer_init (void) +timer1_init (void) { -#ifdef CODEVISION - OCR1AH = ((F_CPU / F_INTERRUPTS) >> 8) & 0xFF; // compare value: 1/10000 of CPU frequency (upper byte) - OCR1AL = ((F_CPU / F_INTERRUPTS) - 1) & 0xFF; // compare value: 1/10000 of CPU frequency (lower byte) -#else // gcc - OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/10000 of CPU frequency -#endif // CODEVISION - TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1 +#if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85: + OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4 + TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4 +#else // ATmegaXX: + OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency + TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1 +#endif -#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega64__) || defined (__AVR_ATmega162__) - TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare (use TIMSK for ATMEGA162) +#ifdef TIMSK1 + TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare #else - TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare (use TIMSK for ATMEGA162) -#endif // __AVR... + TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare +#endif } +#ifdef TIM1_COMPA_vect // ATtiny84 +#define COMPA_VECT TIM1_COMPA_vect +#else +#define COMPA_VECT TIMER1_COMPA_vect // ATmega +#endif + /*--------------------------------------------------------------------------------------------------------------------------------------------------- * timer 1 compare handler, called every 1/10000 sec *--------------------------------------------------------------------------------------------------------------------------------------------------- */ -// Timer 1 output compare A interrupt service routine -#ifdef CODEVISION -interrupt [TIM1_COMPA] void timer1_compa_isr(void) -#else // CODEVISION -ISR(TIMER1_COMPA_vect) -#endif // CODEVISION +ISR(COMPA_VECT) // Timer1 output compare A interrupt service routine, called every 1/15000 sec { (void) irsnd_ISR(); // call irsnd ISR - // call other timer interrupt routines... + // call other timer interrupt routines here... } /*--------------------------------------------------------------------------------------------------------------------------------------------------- * MAIN: main routine *--------------------------------------------------------------------------------------------------------------------------------------------------- */ -#ifdef CODEVISION -// This is the main routine if you use Codevision C Compiler -void -main (void) -{ - IRMP_DATA irmp_data; - - #pragma optsize- - // crystal oscillator division factor: 1 - CLKPR=0x80; - CLKPR=0x00; - #ifdef _OPTIMIZE_SIZE_ - #pragma optsize+ - #endif - - irsnd_init(); // initialize irsnd - timer_init(); // initialize timer - #asm("sei"); // enable interrupts - - for (;;) - { - irmp_data.protocol = IRMP_NEC_PROTOCOL; - irmp_data.address = 0x00FF; - irmp_data.command = 0x0001; - irmp_data.flags = 0; - - irsnd_send_data (&irmp_data); - _delay_ms (1000); - } -} - -#else // gcc - -// This is the main routine if you use GCC Compiler int main (void) { - IRMP_DATA irmp_data; - - irsnd_init(); // initialize irsnd - timer_init(); // initialize timer - sei (); // enable interrupts - - for (;;) - { - irmp_data.protocol = IRMP_NEC_PROTOCOL; - irmp_data.address = 0x00FF; - irmp_data.command = 0x0001; - irmp_data.flags = 0; - - irsnd_send_data (&irmp_data, TRUE); - _delay_ms (1000); - } + IRMP_DATA irmp_data; + + irsnd_init(); // initialize irsnd + timer1_init(); // initialize timer + sei (); // enable interrupts + + for (;;) + { + irmp_data.protocol = IRMP_NEC_PROTOCOL; // use NEC protocol + irmp_data.address = 0x00FF; // set address to 0x00FF + irmp_data.command = 0x0001; // set command to 0x0001 + irmp_data.flags = 0; // don't repeat frame + + irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion + _delay_ms (1000); + } } - -#endif // CODEVISION / gcc