【问题标题】:IR Receiver RC5 with Pic12F1572带 Pic12F1572 的红外接收器 RC5
【发布时间】:2017-01-16 08:53:27
【问题描述】:

我正在使用带有接收器模块 TSOP2438 的 PIC12F1572 构建一个 IR 接收器 我这个项目的目标是通过遥控器接收数据并通过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;
}

【问题讨论】:

    标签: pic uart decoder receiver infrared


    【解决方案1】:

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

    【讨论】:

    • 谢谢@user7424291,我会实施
    • 大家能给我投票吗?我不能再发布问题了...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 2017-10-31
    • 2022-01-16
    相关资源
    最近更新 更多