Terminal 如何通过PIC UART读取PC串行数据帧

Terminal 如何通过PIC UART读取PC串行数据帧,terminal,serial-port,pic,uart,mplab,Terminal,Serial Port,Pic,Uart,Mplab,我试图通过UART从PC接收一帧到PIC12F1572的数据 我的目标是编写一个代码来接收数据,如RGBFF0000\n,这是RGB LED配置。任何人都知道如何执行。我已经编写了一些代码,但我希望使其在逻辑上正确。 我使用PIC12F1572和MPLAB V3.50 高度赞赏代码、更正和提示 提前谢谢 这是我的密码: #include "mcc_generated_files/mcc.h" #define AT_COMMAND_BUFFER_SIZE 256 uint8_t buffer[

我试图通过UART从PC接收一帧到PIC12F1572的数据 我的目标是编写一个代码来接收数据,如RGBFF0000\n,这是RGB LED配置。任何人都知道如何执行。我已经编写了一些代码,但我希望使其在逻辑上正确。 我使用PIC12F1572和MPLAB V3.50 高度赞赏代码、更正和提示 提前谢谢 这是我的密码:

#include "mcc_generated_files/mcc.h"
#define AT_COMMAND_BUFFER_SIZE 256


uint8_t buffer[AT_COMMAND_BUFFER_SIZE];
uint8_t i = 0;
uint8_t receivedByte ;
/*
                         Main application
 */
/*-----------------R.E.C.E.I.V.E.R PIC------------*/
void main(void)
{
    // initialize the device
    SYSTEM_Initialize();


    EUSART_Write(0x61);
    INTERRUPT_GlobalInterruptEnable();      // Enable the Global Interrupts
    INTERRUPT_PeripheralInterruptEnable();     // Enable the Peripheral Interrupts

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();

    while (1)
    {
     if ( UART_DataReady() )            // If data is received,
        {
          receivedByte = EUSART_Read();
          for (i = 0; i<20 ; i++)
          {
            if ( receivedByte == '')
            {
                //My pb is how to start to check the data received over UART RX
            } 


          }

        }

    }
}
#包括“mcc_生成的文件/mcc.h”
#定义AT_命令\u缓冲区\u大小256
uint8_t buffer[AT_COMMAND_buffer_SIZE];
uint8_t i=0;
uint8_t接收字节;
/*
主要应用
*/
/*-----------------R.E.C.E.I.V.E.R图片------------*/
真空总管(真空)
{
//初始化设备
系统初始化();
EUSART_写入(0x61);
中断_globalinterrupEnable();//启用全局中断
中断_peripheraldinterruptenable();//启用外围中断
//禁用全局中断
//中断_GlobalInterruptDisable();
//禁用外围中断
//中断\外围设备中断禁用();
而(1)
{
if(UART_DataReady())//如果接收到数据,
{
receivedByte=EUSART_Read();

对于(i=0;i您将在每个命令末尾发送新行字符
\n
,因此请将
receivedbyte
读到
\n
,并将其存储在新数组中。然后设置一个标志以显示有效的命令接收。处理新命令后,清除此标志

 if ( UART_DataReady() )            // If data is received,
    {
        receivedByte = EUSART_Read();
        for (i = 0; i<20 ; i++)
        {
            if ( receivedByte != '\n')
            {
                data[i] = receivedByte;

            }
            else{
                data[i] = '\0';
                data_flag = 1;
                break;
            }
        }

    }
if(UART\u DataReady())//如果收到数据,
{
receivedByte=EUSART_Read();
对于(i=0;i,答案如下:

#include "mcc_generated_files/mcc.h"
#include <stdlib.h>
#include <stdio.h>
#include "atoh.h"
#include "LED.h"
#define _XTAL_FREQ 16000000
#define FRAMESIZE 20
void main(void)
{
   uint8_t data,i,j,got_char;


   uint8_t value;
   uint8_t RX_Buffer[FRAMESIZE];


    // 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[18] = '\n';
            RX_Buffer[i] = 0;
            EUSART_WriteAnArrayOfBytes(RX_Buffer);
        }
#包括“mcc_生成的文件/mcc.h”
#包括
#包括
#包括“atoh.h”
#包括“LED.h”
#定义频率16000000
#定义帧大小20
真空总管(真空)
{
uint8_t数据,i,j,got_char;
uint8_t值;
uint8_t RX_缓冲区[帧大小];
//初始化设备
系统初始化();
中断_globalinterrupEnable();//启用全局中断
中断_peripheraldinterruptenable();//启用外围中断
而(1)
{
if(EUSART_数据就绪)
{

对于(i=0;iThanks for the reply,我尝试了这个,但是我看不到接收数据,现在我更想看看是否在缓冲区数据[]中接收到数据。我如何使用它来闪烁我的LED。谢谢,如果你对此有一些解决方案:)我检查并找到了直到receivedByte=EUSART_Read();代码正常工作,之后它不会进入for循环,因此无法检查if(receivedByte!='\n'):(我正在使用Hterm发送数据,为什么不在ISR中写入此内容。我认为这是最有效的方法。设置data_标志后,您必须退出for循环,因为数据将在那时准备好。我对我的答案做了一些更改,请检查……好的,我检查了……实际上我从中得到了答案……thanx by d way..我正在寻找答案。)将输入ascii从我从UART获得的数据转换为十六进制,…如果您知道提示或解决方案,我将非常感谢阅读。。。