2017-01-16 22 views
2

私は受信機モジュールTSOP2438でIR受信機を構築しています。 このプロジェクトの目的は、リモートコントロールでデータを受信し、UART経由でPCに送信することです。 コードと私はそれをテストしている私はUARTを介して正常な値を送信することができますが、Somewhereisは間違っているので、私はリモートコントロールのコマンドに関する16進数の値を受け取ることができません 誰も私のコードを見て、 は、ここで私はあなたが文字列に変換せずに六角値を送信しているためであると考える私のコードIR受信機RC5 with Pic12F1572

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; 
} 

答えて

1

です。 PC端末でこのHex値を印刷する場合は、まずASCII文字列に変換する必要があります。

+0

ありがとう@ user7424291、、私は – Garryp

+0

を実装しますあなたはすべて私を与えることができます投票してください??もう質問は投稿できません... – Garryp

関連する問題