我正在尝试使微控制器与我桌面上的程序进行通信。我在两端都使用带有 Xbee 无线电的串行端口连接。
当我从微控制器向桌面发送一些东西并且桌面上的程序然后将一些东西发送回微控制器时,通信工作正常。
但是,当我要求将信息从控制器连续发送到桌面程序时,直到桌面程序发送特定的答案,它就不起作用了。
这是我正在谈论的代码:
    unsigned char ans = 'N';
    unsigned int count = 0;
    void main(void)
    {
        while(1)
        {
            if(count == 0)
            {
                Configure();
                count = 1;
            }
                  //there is some more code here but is irrelevant to the serial communication
         }
    }
void Configure()
{
    //Repeat this until the user accepts the sent string as correct
    while(ans == 'N')
    {
        BuildString();
        Send();
        Receive();
    }
}
void Send()
{
    unsigned int i;
    TMOD = 0x20;
    TH1 = 0xFD;
    SCON = 0x50;
    TR1 = 1;
    for(i=0; i<4; i++)
    {
        SBUF = toSend[i];
        while(TI == 0);
        TI = 0;
    }   
}
void Receive()
{
    unsigned int j;
    TMOD = 0x20;
    TH1 = 0xFD;
    SCON = 0x50;
    TR1 = 1;
    for(j=0; j<2; j++)
    {
        while(RI == 0);
        Received[j] = SBUF;
        RI = 0; 
    }
    if(count == 0)
        ans = Received[1];
    else
    {   
        RunType = Received[0];
        Move = Received[1];
    }
}
BuildString() 函数只是根据一些传感器输入构造一个字符串。发送和接收函数通常工作正常,但是当我需要它们连续发送和接收时,就像上面的 Configure() 函数一样,它不起作用。
有什么建议么?我真的很感激他们。