AVR/Source/SIRC

From OmegaV-wiki
Jump to: navigation, search

SIRC Transmitter

This code can be used to transmit data to an IR receiver, for example a TV or DVD player. It has been setup for the Butterfly (ATmega169), but can be used with any AVR.

sirc.c

<source lang=c>

  1. include <avr/io.h>
  2. include <util/delay_basic.h>
  1. define UTPORT PORTD
  2. define UTDDR DDRD
  3. define UTPIN PD0

//Transmit Sony Ir Code (SIRC) //Based on http://users.pandora.be/davshomepage/ //Designed for ATmega 169 @ 8Mhz

void sendBit(unsigned char bit); void sendIR(char adr, char cmd);

int main(void){ UTDDR |= (1<<UTPIN);

while(1){ for(char i=64; i<71; i++){ sendIR(0b00001, i); } } }


void sendIR(char adr, char cmd){ sendBit(3);

sendBit((cmd>>0) & 1); sendBit((cmd>>1) & 1); sendBit((cmd>>2) & 1); sendBit((cmd>>3) & 1); sendBit((cmd>>4) & 1); sendBit((cmd>>5) & 1); sendBit((cmd>>6) & 1);


sendBit((adr>>0) & 1); sendBit((adr>>1) & 1); sendBit((adr>>2) & 1); sendBit((adr>>3) & 1); sendBit((adr>>4) & 1);

//Wait 40ms _delay_loop_2(61000); _delay_loop_2(15923); }

void sendBit(unsigned char bit){ char length = 20*(bit+1); UTPORT &= ~(1<<UTPIN); _delay_loop_2(1200); //Wait 4000 clock cycles for(char i = 0; i<length; i++){ UTPORT |= (1<<UTPIN); _delay_loop_2(30); //Wait 100 clock cycles UTPORT &= ~(1<<UTPIN); _delay_loop_2(30); //Wait 100 clock cycles } }

</source>