IR Decoder Serial out

Привет всем.
Сделал IR декодер
все работает
Но хотелось бы ,чтобы данные параллельно выводились на ком-порт
Кто может поправить исходник?

/* IR Remote Control Detective v5 - see http://www.technoblogy.com/show?24A9

   David Johnson-Davies - www.technoblogy.com - 28th January 2024
   ATtiny85 @ 1 MHz (internal oscillator; BOD disabled)
   
   CC BY 4.0
   Licensed under a Creative Commons Attribution 4.0 International license: 
   http://creativecommons.org/licenses/by/4.0/
*/

#include <Wire.h>

// OLED I2C 128 x 32 monochrome display **********************************************

int Scale = 2;
const int OLEDAddress = 0x3C;

// Initialisation sequence for OLED module
int const InitLen = 24;
const unsigned char Init[InitLen] PROGMEM = {
  0xAE, // Display off
  0xD5, // Set display clock
  0x80, // Recommended value
  0xA8, // Set multiplex
  0x1F,
  0xD3, // Set display offset
  0x00,
  0x40, // Zero start line
  0x8D, // Charge pump
  0x14,
  0x20, // Memory mode
  0x01, // Vertical addressing
  0xA1, // 0xA0/0xA1 flip horizontally
  0xC8, // 0xC0/0xC8 flip vertically
  0xDA, // Set comp ins
  0x02,
  0x81, // Set contrast
  0x7F, // 0x00 to 0xFF
  0xD9, // Set pre charge
  0xF1,
  0xDB, // Set vcom detect
  0x40,
  0xA6, // Normal (0xA7=Inverse)
  0xAF  // Display on
};

const int data = 0x40;
const int single = 0x80;
const int command = 0x00;

void InitDisplay () {
  Wire.beginTransmission(OLEDAddress);
  Wire.write(command);
  for (uint8_t c=0; c<InitLen; c++) Wire.write(pgm_read_byte(&Init[c]));
  Wire.endTransmission();
}

// Graphics **********************************************

// Character set for text - stored in program memory
const uint8_t CharMap[96][6] PROGMEM = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 
{ 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00 }, 
{ 0x00, 0x07, 0x00, 0x07, 0x00, 0x00 }, 
{ 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00 }, 
{ 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00 }, 
{ 0x23, 0x13, 0x08, 0x64, 0x62, 0x00 }, 
{ 0x36, 0x49, 0x56, 0x20, 0x50, 0x00 }, 
{ 0x00, 0x08, 0x07, 0x03, 0x00, 0x00 }, 
{ 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00 }, 
{ 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00 }, 
{ 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00 }, 
{ 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00 }, 
{ 0x00, 0x80, 0x70, 0x30, 0x00, 0x00 }, 
{ 0x08, 0x08, 0x08, 0x08, 0x08, 0x00 }, 
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, 
{ 0x20, 0x10, 0x08, 0x04, 0x02, 0x00 }, 
{ 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00 }, 
{ 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00 }, 
{ 0x72, 0x49, 0x49, 0x49, 0x46, 0x00 }, 
{ 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00 }, 
{ 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00 }, 
{ 0x27, 0x45, 0x45, 0x45, 0x39, 0x00 }, 
{ 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00 }, 
{ 0x41, 0x21, 0x11, 0x09, 0x07, 0x00 }, 
{ 0x36, 0x49, 0x49, 0x49, 0x36, 0x00 }, 
{ 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00 }, 
{ 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 }, 
{ 0x00, 0x40, 0x34, 0x00, 0x00, 0x00 }, 
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, 
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x00 }, 
{ 0x00, 0x41, 0x22, 0x14, 0x08, 0x00 }, 
{ 0x02, 0x01, 0x59, 0x09, 0x06, 0x00 }, 
{ 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00 }, 
{ 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00 }, 
{ 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00 }, 
{ 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00 }, 
{ 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00 }, 
{ 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00 }, 
{ 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00 }, 
{ 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00 }, 
{ 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00 }, 
{ 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00 }, 
{ 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00 }, 
{ 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00 }, 
{ 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00 }, 
{ 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00 }, 
{ 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00 }, 
{ 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00 }, 
{ 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00 }, 
{ 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00 }, 
{ 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00 }, 
{ 0x26, 0x49, 0x49, 0x49, 0x32, 0x00 }, 
{ 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00 }, 
{ 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00 }, 
{ 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00 }, 
{ 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00 }, 
{ 0x63, 0x14, 0x08, 0x14, 0x63, 0x00 }, 
{ 0x03, 0x04, 0x78, 0x04, 0x03, 0x00 }, 
{ 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00 }, 
{ 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00 }, 
{ 0x02, 0x04, 0x08, 0x10, 0x20, 0x00 }, 
{ 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00 }, 
{ 0x04, 0x02, 0x01, 0x02, 0x04, 0x00 }, 
{ 0x40, 0x40, 0x40, 0x40, 0x40, 0x00 }, 
{ 0x00, 0x03, 0x07, 0x08, 0x00, 0x00 }, 
{ 0x20, 0x54, 0x54, 0x78, 0x40, 0x00 }, 
{ 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00 }, 
{ 0x38, 0x44, 0x44, 0x44, 0x28, 0x00 }, 
{ 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00 }, 
{ 0x38, 0x54, 0x54, 0x54, 0x18, 0x00 }, 
{ 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00 }, 
{ 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00 }, 
{ 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00 }, 
{ 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00 }, 
{ 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00 }, 
{ 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00 }, 
{ 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00 }, 
{ 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00 }, 
{ 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00 }, 
{ 0x38, 0x44, 0x44, 0x44, 0x38, 0x00 }, 
{ 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00 }, 
{ 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00 }, 
{ 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00 }, 
{ 0x48, 0x54, 0x54, 0x54, 0x24, 0x00 }, 
{ 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00 }, 
{ 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00 }, 
{ 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00 }, 
{ 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00 }, 
{ 0x44, 0x28, 0x10, 0x28, 0x44, 0x00 }, 
{ 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00 }, 
{ 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00 }, 
{ 0x00, 0x08, 0x36, 0x41, 0x00, 0x00 }, 
{ 0x00, 0x00, 0x77, 0x00, 0x00, 0x00 }, 
{ 0x00, 0x41, 0x36, 0x08, 0x00, 0x00 }, 
{ 0x02, 0x01, 0x02, 0x04, 0x02, 0x00 }, 
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 }
};

void ClearDisplay () {
  Wire.beginTransmission(OLEDAddress);
  Wire.write(command);
  // Set column address range
  Wire.write(0x21); Wire.write(0); Wire.write(127);
  // Set page address range
  Wire.write(0x22); Wire.write(0); Wire.write(3);
  Wire.endTransmission();
  // Write the data in 16 32-byte transmissions
  for (int i = 0 ; i < 32; i++) {
    Wire.beginTransmission(OLEDAddress);
    Wire.write(data);
    for (int i = 0 ; i < 32; i++) Wire.write(0);
    Wire.endTransmission();
  }
}

// Converts bit pattern abcdefgh into aabbccddeeffgghh
int Stretch (int x) {
  x = (x & 0xF0)<<4 | (x & 0x0F);
  x = (x<<2 | x) & 0x3333;
  x = (x<<1 | x) & 0x5555;
  return x | x<<1;
}

// Plots a character; line = 0 to 3; column = 0 to 131
void PlotChar(int c, int line, int column) {
  Wire.beginTransmission(OLEDAddress);
  Wire.write(command);
  // Set column address range
  Wire.write(0x21); Wire.write(column); Wire.write(column + Scale*6 - 1);
  // Set page address range
  Wire.write(0x22); Wire.write(line); Wire.write(line + Scale - 1);
  Wire.endTransmission();
  Wire.beginTransmission(OLEDAddress);
  Wire.write(data);
  for (uint8_t col = 0 ; col < 6; col++) {
    int bits = pgm_read_byte(&CharMap[c-32][col]);
    if (Scale == 1) Wire.write(bits);
    else {
      bits = Stretch(bits);
      for (int i=2; i--;) { Wire.write(bits); Wire.write(bits>>8); }
    }
  }
  Wire.endTransmission();
}

// Plot text starting at the current plot position
void PlotText (PGM_P s, int line, int column) {
  int p = (int)s;
  while (1) {
    char c = pgm_read_byte(p++);
    if (c == 0) return;
    PlotChar(c, line, column);
    column = column + 6 * Scale;
  }
}

// Display a 4-digit hexadecimal number starting at line, column
void PlotHex (unsigned int hex, int line, int column) {
  for (unsigned int d=0x1000; d>0; d=d/16) {
    uint8_t h = (hex/d) % 16;
    char c = (h < 10) ? h + '0' : h - 10 + 'A';
    PlotChar(c, line, column);
    column = column + Scale*6;
  }
}

// NEC **********************************************

void ReceivedCode(char IRtype, unsigned int Address, unsigned int Command) {
  if (IRtype>32) {
    PlotChar(IRtype,1,0);
    Scale = 1; PlotChar(' ',3,0); PlotChar(' ',3,6);
    Scale = 2;
  }
  else {
     PlotChar('S',1,0);
     Scale = 1; PlotChar((IRtype/10)+'0',3,0); PlotChar((IRtype%10)+'0',3,6);
     Scale = 2;
  }
  PlotHex(Address, 0, 72);
  PlotHex(Command, 2, 72);
}

// Globals
volatile unsigned long RecdData;
volatile int Bit, Edge;
volatile char IRtype;
  
// Protocol timings
const int Micros = 64;     // Number of microseconds per TCNT1 count

const int SonyIntro = 2400/Micros;
const int SonyMean = 900/Micros;

const int NECIntro = 9000/Micros;
const int NECGap = 4500/Micros;
const int NECPulse = 562/Micros;
const int NECMean = 1125/Micros;

const int SamsungIntro = 5000/Micros;
const int SamsungGap = 5000/Micros;

const int RC5Half = 889/Micros;    // 0.889ms
const int RC5Full = 1778/Micros;
const int RC5Mean = 1334/Micros;

// Interrupt service routine - called on Timer/Counter1 overflow
ISR(TIMER1_OVF_vect) {
  ReceivedCode(Bit, RecdData>>7, RecdData & 0x7F);
  TIMSK = TIMSK & ~(1<<TOIE1);                  // Disable overflow interrupt
  TCNT1 = 250;
}

// Interrupt service routine - called on each edge of PB3
ISR(PCINT0_vect) {
  static int Mid;  // Edge: 0 = falling, 1 = rising
  int Time = TCNT1;
  if (TIFR & 1<<TOV1) { IRtype = 0; Edge = 1; }        // Overflow
  else if (Edge != (PINB>>PINB3 & 1));                 // Ignore if wrong edge
  else if (IRtype == 0) {
  
    // End of intro pulse
    if (abs(Time - RC5Half) < 5) {
      IRtype = 'R'; RecdData = 0x2000; Bit = 12; Edge = 0; Mid = 0;
    } else if (abs(Time - RC5Full) < 5) {
      IRtype = 'R'; RecdData = 0x2000; Bit = 11; Edge = 0; Mid = 1;
    } else if ((abs(Time - SonyIntro) < 5) && (Edge == 1)) {
      IRtype = 'S'; RecdData = 0; Bit = 0;
      TIMSK = TIMSK | 1<<TOIE1;                        // Enable overflow interrupt
    } else if (abs(Time - SamsungIntro) < 18) {
      IRtype = 'M'; RecdData = 0; Bit = -1; Edge = 0;  // Ignore first falling edge
    } else if (abs(Time - NECIntro) < 18) { 
      IRtype = 'N'; RecdData = 0; Bit = -1; Edge = 0;  // Ignore first falling edge
    }
  
  // Data bit
  } else if (IRtype == 'R') {
    Edge = !Edge;
    if ((Time < RC5Mean) && Mid) {
      Mid = 0;
    } else {
      Mid = 1;
      RecdData = RecdData | ((unsigned long) Edge<<Bit);
      if (Bit == 0) ReceivedCode('R', RecdData>>6 & 0x1F,
        (~(RecdData>>6) & 0x40) | (RecdData & 0x3F));
      Bit--;
    }
  } else if (IRtype == 'S') {
    if (Time > SonyMean) RecdData = RecdData | ((unsigned long) 1<<Bit);
    Bit++;
  } else if ((IRtype == 'N') || (IRtype == 'M')) {
    if (Time > NECMean && Bit >= 0) RecdData = RecdData | ((unsigned long) 1<<Bit);
    Bit++;
    if (Bit == 32) ReceivedCode(IRtype, RecdData & 0xFFFF, RecdData>>16);
  }
  
  TCNT1 = 0;                  // Clear counter
  TIFR = TIFR | 1<<TOV1;      // Clear overflow
}

// Setup **********************************************
  
void setup() {
  Wire.begin();
  InitDisplay();
  ClearDisplay();
  // Set up Timer/Counter1 (assumes 1MHz clock)
  TCCR1 = 7<<CS10;            // No compare matches ; /64
  // Set up pin change interrupt on PB3
  PCMSK = 1<<PCINT3;          // Interrupt on PB3
  GIMSK = 1<<PCIE;            // Enable pin change interrupts
  // Headings
  PlotText(PSTR("Adr:"),0,24);
  PlotText(PSTR("Cmd:"),2,24);
}

void loop() {
  // Everything done under interrupt!
}

во первых вставьте код по правилам форума.
во вторых - покажите ВАШУ попытку добиться желаемого и обьясните что в ней не работает.
найти чей то код и попросить его за вас его изменить - не является вашей попыткой …

1 лайк

Сколько платишь?

Что это? )))
Код не компилируется вообще…

Смельчак, который решится взяться за “это” сначала на трахается с тем, чтобы код вообще начал компилироваться…

Скетч использует 3624 байт (44%) памяти устройства. Всего доступно 8192 байт.
Глобальные переменные используют 54 байт (10%) динамической памяти, оставляя 458 байт для локальных переменных. Максимум: 512 байт.

Схему без вывода на ком порт взял тут Technoblogy - IR Remote Control Detective [Updated]
там же и исходниеи
Откомпилировал,прошил с помощью USBASP и спаял на макетке
все работает, но мне нужно чтобы и в компорт выводило значение

Вас зовут

?

Хорошо говорите по-русски!

1 лайк

Повторил за кем-то и то неплохо.