带 Pic12F1572 的红外接收器 RC5

IR Receiver RC5 with Pic12F1572

我正在使用 PIC12F1572 和接收器模块 TSOP2438 构建红外接收器 我的这个项目objective是通过远程控制接收数据并通过UART将其发送到PC.. 我已经完成了代码并且正在测试它我可以通过 UART 发送正常值但是某处是错误的所以我无法接收关于远程控制命令的十六进制值 谁能看到我的代码并告诉我哪里出错了? 这是我的代码

 void main(void)
{   
    OSCILLATOR_Initialize();          // 0x78 for Fosc = 16Mhz 
    PIN_MANAGER_Initialize();         //All port pins Digital and input
    EUSART_Initialize();
    INTCONbits.IOCIF = 0;            // Interrupt on-change Flag
    INTCONbits.PEIE = 1;            //SEt Peripheral Interrupt
    INTCONbits.GIE = 1;             //Set Global Interrupt 
  //while(!OSCSTATbits.HFIOFS);     //Check here or wait here to OSC stable/ 0.5% accuracy

    TRISAbits.TRISA2 = 1;           //Configure R1 as input

 // uint16_t Input_buffer [20];

  EUSART_Write(0x40);             // 0x40 = @ some flag


   while(1)
  {
    count = 0;
    //while((IR_PIN));                //IR_PIN receives an IR signal its output pin goes from logic 1 to logic 0
                                    //which causes the microcontroller to start reading the IR signal using the function. decode()
    EUSART_Write(0x41); 
   //while(IR_PIN);

    if(Decode())                    //check if RC5 decoding- new data is arrived
    {

        EUSART_Write(0x42); 

        toggle_bit = bit_test(IR_Code, 11);
        address = (IR_Code >> 6) & 0x1F;
        command = IR_Code & 0x3F;

        EUSART_Write(toggle_bit);
        EUSART_Write(address);
        EUSART_Write(command);

        EUSART_Write(0x43);


    }
  }
}

/*----------*/
uint8_t Measure_space()
{
  TMR0_Initialize();

  while(IR_PIN && (count < 2000))
    count = TMR0_ReadTimer();               //Read timer value and store it in count value
  if((count > 1999) || (count < 700))
    return 0;                               //0 = If width is out of range
  if(count > 1200)
    return 1;                               //1 = If width is long
  else
    return 2;                               //2 = If the width is short
}

uint8_t Decode()
{
  uint8_t i = 0, check;
  mid1:
  check = Measure_Pulse();
  if(check == 0)
    return FALSE;
  bit_set(IR_Code, 13 - i);
  i++;

  if(i > 13)
   return TRUE;

  if(check == 1)
    goto mid0;
  else
    goto start1;

  mid0:
  check = Measure_space();
  if((check == 0) && (i != 13))

    return FALSE;

  bit_clear(IR_Code, 13 - i);
  i++;

  if(i > 13) return TRUE;

  if(check == 1)
    goto mid1;
  else
    goto start0;

 start1:
  check = Measure_space();
  if(check != 2)
    return FALSE;
  goto mid1;
  start0:
  check = Measure_Pulse();
  if(check != 2)
    return FALSE;
  goto mid0;
}

我认为这是因为您发送的是十六进制值而没有转换为字符串。如果要在 PC 终端打印此十六进制值,首先必须将其转换为 ASCII 字符串。