#include <io.h>
#include <delay.h>
#include <stdint.h>

#define RF_ALPHA        350 //us - Protocol 1

#define RF_REPEAT       10

#define RF_DATA_LEN     24 //bit

#define RF_DATA         PORTC.0
#define RF_DATA_DDR     DDRC.0

void RF_sendSync(void);
void RF_sendZero(void);
void RF_sendOne(void);

void RF_sendCode(uint32_t code);


void main(void)
{

RF_DATA_DDR = 1;

RF_sendCode(0xAABBCC);

while (1)
    {
    // Please write your application code here

    }
}

void RF_sendCode(uint32_t code) {
  uint8_t i;            
  uint8_t bitIndex;
  uint32_t tempCode;
  
  for (i = 0; i < RF_REPEAT; i++) {
    tempCode = code;
    RF_sendSync();
    for (bitIndex = 0; bitIndex < RF_DATA_LEN; bitIndex++) {
      // MSB-First  
      if (tempCode & (1 << RF_DATA_LEN)) {
        RF_sendOne();
      }              
      else {
        RF_sendZero();
      }
    }          
  }
}

void RF_sendSync(void) {
  RF_DATA = 1;
  delay_us(RF_ALPHA * 1);
  RF_DATA = 0;
  delay_us(RF_ALPHA * 31);
}
void RF_sendZero(void) {
  RF_DATA = 1;
  delay_us(RF_ALPHA * 1);
  RF_DATA = 0;
  delay_us(RF_ALPHA * 3);
}
void RF_sendOne(void) {
  RF_DATA = 1;
  delay_us(RF_ALPHA * 3);
  RF_DATA = 0;
  delay_us(RF_ALPHA * 1);
}
