红外接收器 RC5 与 Pic12F1572



我正在构建一个带有接收器模块PIC12F1572的红外接收器TSOP2438我这个项目的目标是通过远程控制接收数据,并通过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字符串。

相关内容

  • 没有找到相关文章

最新更新