2017-02-06 1 views
1

RGB LED 프로젝트에서 작업 중이며 PIC12F1572로 제어됩니다. 내가 사용하고있는 소프트웨어는 HiTech C 컴파일러가있는 MPLAB IDE입니다. 계획은 직렬 통신을 사용하여 PIC에 LED RGB 조합 데이터 명령을 보내 변수의 LED 깜박임과 빛이 나는 UART 통신을 설정할 수있게했습니다. 모든 기능 또는 단계 코드가 옳습니다. 문법 및 리눅스 명령 줄 터미널에서 컴파일하는 경우 작동합니다. 및 MPLAB.I 등록을 사용하여 시뮬레이션하려고하면 또한 시뮬레이션에서 실행하려면 (사람이 알고 어떻게 등록 주입 actuallly MPLAB에서 작동합니까?) 내가 디버그하려고 할 때 내가 직면하는 문제. 그것은 컴파일하지만 작동하지 않습니다 여기 내 코드입니다 : 어떤 아이디어 또는 문제에 대한 힌트를 높이 평가 될 것입니다. [계층 적 방법] 코드를 삽입하는 것이 개인적으로 수수료가 부과 될 수 있습니다. 감사합니다! 는 UART 프레임을 수신하고 다시 반향 및 저장 데이터가 깜빡 만든다부터, 내가 성공할 수 있어요 이것은 내가 계층 적 방식으로 여기에 차 단계에서 원하던 그래서 때까지PIC12, MPLAB 및 UART가 포함 된 임베디드 응용 프로그램에 대한 출력이 없음

#include <xc.h> 
#include "mcc.h" 
#include "LED.h" 
#include "tmr0.h" 
#include "interrupt_manager.h" 

void SetLedColor(uint16_t R_color, uint16_t G_color, uint16_t B_color); 

void main(void) 
{ 
    uint8_t data, i, j; 

    uint16_t R_value, G_value, B_value; 
    uint8_t value; 
    uint8_t RX_Buffer[FRAMESIZE] ,RGB_data[6] ,HEX_data[6]; 

    // initialize the device 
    SYSTEM_Initialize(); 
    INTERRUPT_GlobalInterruptEnable();   // Enable the Global Interrupts 
    INTERRUPT_PeripheralInterruptEnable(); // Enable the Peripheral Interrupts 

    while (1) 
    { 
     // EUSART_Write(0x61); 
     while (!RCIF) 
     { 
      data = EUSART_Read();      // Read received character 
      for (i = 0; i < FRAMESIZE; i++) 
      { 
       RX_Buffer[i] = data; 
      } 

      EUSART_Write(data); 
     } 

     //check if any data is received 

     for (j = 0; j = 5; j++)  // get the RGB value in the separate array 
     { 
      RGB_data[j] = RX_Buffer[j + 3]; 
      HEX_data[value] = RGB_data[j]/16; 
     } 

     if (RX_Buffer[0] == 'R' && RX_Buffer[FRAMESIZE - 1] == '\n') 
     { 
      //ASCII to HEX separate values 

      // uint32_t number = (uint32_t)strtol(HEX_data, NULL, 16); 
      // R_value = number >>16; 
      // G_value = (number & 0xffff) >> 8; 
      // B_value = (number & 0x0000FF); 

      R_value = (uint16_t) atoh(HEX_data[0], HEX_data[1]); 
      G_value = (uint16_t) atoh(HEX_data[2], HEX_data[3]); 
      B_value = (uint16_t) atoh(HEX_data[4], HEX_data[5]); 

     } 

     SetLedColor(R_value, G_value, B_value); 
    } 

} 

void SetLedColor(uint16_t R_color, uint16_t G_color, uint16_t B_color) 
{ 
    if (R_color == 0xFF) 
    { 
     LATAbits.LATA2 = 1; 
    } 
    else 
    { 
     LATAbits.LATA2 = 0; 
    } 

    if (G_color == 0xFF) 
    { 

     LATAbits.LATA4 = 1; 
    } 
    else 
    { 
     LATAbits.LATA4 = 0; 
    } 
    if (B_color == 0xFF) 
    { 

     LATAbits.LATA5 = 1; 
    } 
    else 
    { 
     LATAbits.LATA5 = 0; 
    } 
} 
+0

_doesn't_ ..... 조금 정성 들여 주시겠습니까? – LPs

+0

'uint8_t RX_Buffer [], RGB_data [], HEX_data [];'... ??????? 당신은 크기가없는 배열을 선언했습니다 ..... – LPs

+0

목적은 UART로부터받은 데이터로 LED를 밝게하는 것입니다. 그리고 각 작업의 모듈을 분리하면 "UART"라고 말할 수 있습니다 -> 작동합니다. 나는 데이터를 수신 할 수 있고 시리얼 터미널로 다시 되돌릴 수있다. 변환 ASCII는 16 진수로 작동한다. LED prog는 테스트된다 .. 내가 믿는 모든 것들이 코드를 함께 넣을 때 .. 데이터가 수신되지 않고 멈춘다. (시스템 초기화 기능은 이전에 테스트되었습니다.) – Garryp

답변

0

#include "mcc_generated_files/mcc.h" 
#include <stdlib.h> 
#include <stdio.h> 
#include "atoh.h" 
#include "LED.h" 
#define _XTAL_FREQ 16000000 
#define FRAMESIZE 19 

void main(void) 
{ 
    uint8_t data,i,j,got_char; 

    uint8_t R_value, G_value ,B_value; 
    uint8_t value; 
    uint8_t RX_Buffer[FRAMESIZE]; 
    uint8_t RGB_data[6] ,HEX_data[6]; 

    // initialize the device 
    SYSTEM_Initialize(); 
    INTERRUPT_GlobalInterruptEnable();      // Enable the Global Interrupts 
    INTERRUPT_PeripheralInterruptEnable();     // Enable the Peripheral Interrupts 

    while (1) 
{ 

     if (EUSART_DataReady) 
     { 
      for (i = 0; i<FRAMESIZE; i++) 
      { 
       RX_Buffer[i] = EUSART_Read(); 
       if (RX_Buffer[i] == '\n') 
        break; 
      } 

      RX_Buffer[i] = '\n';      //append '\n' at the end of stoaring array for detection of frame 
      RX_Buffer[i+1] = '\0';      // End of an array 
      EUSART_WriteAnArrayOfBytes(RX_Buffer); 


     if(RX_Buffer[0]=='R' && RX_Buffer[FRAMESIZE-2] == '\n') //check for correct frame 
      { 

      LATAbits.LATA2 = 1; 
      __delay_ms(2000); 
      LATAbits.LATA2 = 0; 
      __delay_ms(1000); 
      } 
     } 

    }  
관련 문제