This commit is contained in:
2026-07-07 22:07:44 +02:00
commit 5f31e98d5c
8 changed files with 5230 additions and 0 deletions

156
irsnd-main-avr.c Normal file
View File

@@ -0,0 +1,156 @@
/*---------------------------------------------------------------------------------------------------------------------------------------------------
* irsnd-main-avr.c - demo main module to test IRSND encoder on AVRs
*
* Copyright (c) 2010-2020 Frank Meyer - frank(at)fli4l.de
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
#include "irsnd.h"
#ifndef F_CPU
# error F_CPU unknown
#endif
void
timer1_init (void)
{
#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
#ifdef TIMSK1
TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
#else
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
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
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 here...
}
/*---------------------------------------------------------------------------------------------------------------------------------------------------
* MAIN: main routine
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
int
main (void)
{
IRMP_DATA irmp_data;
irsnd_init(); // initialize irsnd
timer1_init(); // initialize timer
sei (); // enable interrupts
DDRA = 0x00;
PORTA = 0xFF;
DDRB = 0xFF;
PORTB = 0xFF;
irmp_data.protocol = IRMP_RC6_PROTOCOL; // use NEC protocol
irmp_data.flags = 0; // don't repeat frame
//
for (;;)
{
//önöff
if(~PINA & (1<<0)){
PORTB &= ~0x01;
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x000C; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 0x01;
}
//OK
if(~PINA & (1<<1)){
PORTB &= ~(1<<1);
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x005C; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 1<<1;
}
//ambi
if(~PINA & (1<<2)){
PORTB &= ~(1<<2);
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x000A; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 1<<2;
}
//rechts
if(~PINA & (1<<3)){
PORTB &= ~(1<<3);
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x005B; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 1<<3;
}
//links
if(~PINA & (1<<4)){
PORTB &= ~(1<<4);
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x005A; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 1<<4;
}
//runter
if(~PINA & (1<<5)){
PORTB &= ~(1<<5);
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x0059; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 1<<5;
}
//hoch
if(~PINA & (1<<6)){
PORTB &= ~(1<<6);
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x0058; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 1<<6;
}
//Menu
if(~PINA & (1<<7)){
PORTB &= ~(1<<7);
irmp_data.address = 0x0000; // set address to 0x00FF
irmp_data.command = 0x0057; // set command to 0x0001
irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion
_delay_ms (200);
PORTB |= 1<<7;
}
}
}