English 中文(简体)
如何适当接受美加澳新学院的护卫
原标题:How to receive a string properly from UART

I sending a string like this: $13,-14,283,4,-4,17,6,-240,-180#

但是,由于缓冲的超负荷、我如何得到全方位或我如何在每一次逐读后加以澄清,所以没有显示。

// get a character string 
char *getsU2(char *s, int len) { 
    char *p = s; // copy the buffer pointer 
    do {
        *s = getU2(); // get a new character 
        if (( *s== 
 ) || (*s== 
 )) // end of line... 
            break; // end the loop s++;

        // increment the buffer pointer 
        len--;
    } while (len>1); // until buffer is full 

    *s =   ; // null terminate the string 

    return p; // return buffer pointer
} 


// get a character string
char *getsU2(char *s, int len) { 
    char *p = s; // copy the buffer pointer 
    do {
        *s = getU2(); // get a new character 

        if (( *s== 
 ) || (*s== 
 )) // end of line... 
            break; // end the loop 

        s++;     

        // increment the buffer pointer 
        len--; 
    } while (len>1); // until buffer is full

    *s =   ; // null terminate the string      

    return p;    // return buffer pointer
}



char getU2(void) { 
if(U2STAbits.OERR == 1) 
{     U2STAbits.OERR = 0; } 
while (!U2STAbits.URXDA);    // wait for new character to arrive return U2RXREG;
                             // read character from the receive buffer }

getsU2(buffer,sizeof(buffer));
问题回答

使用UART的管道中断。 下面的法典适用于事先知情同意24H;适当修改。

在你的职责中:

IFS0bits.U1RXIF = 0;        // clear rx interrupt flag
IFS0bits.U1TXIF = 0;        // clear tx interrupt flag

IEC0bits.U1RXIE = 1;        // enable Rx interrupts
IPC2bits.U1RXIP = 1;
IEC0bits.U1TXIE = 1;        // enable tx interrupts
IPC3bits.U1TXIP = 1;   

1. 创建阻断手,把 by带入缓冲或 que:

void __attribute__((__interrupt__, auto_psv)) _U1RXInterrupt(void)
{
    char bReceived;

    // Receive Data Ready
    // there is a 4 byte hardware Rx fifo, so we must be sure to get all read bytes    
    while (U1STAbits.URXDA)
    {
        bReceived = U1RXREG;

        // only usethe data if there was no error
        if ((U1STAbits.PERR == 0) && (U1STAbits.FERR == 0))
        {
             // Put your data into a queue
             FIFOPut(bReceived);

        }

    }    

    IFS0bits.U1RXIF = 0;        // clear rx interrupt flag 
}

您的问询守则遵循这些方针:

#define FIFO_SIZE 64

char pbBuffer[FIFO_SIZE];
char *pbPut;
char *pbGet;

void FIFOInit(void)
{
    pbPut = pbBuffer;
    pbGet = pbBuffer;
}

void FIFOPut(char bInput)
{
    *pbPut = bInput;
    pbPut++;

    if (pbPut >= (pbBuffer + FIFO_SIZE))
        pbPut = pbBuffer;
}

char FIFOGet(void)
{
    char bReturn;

    bReturn = *pbGet;
    pbGet++;

    if (pbGet>= (pbBuffer + FIFO_SIZE))
        pbGet= pbBuffer;
}   

显然,应当放弃国际不动产业联合会的职能,防止过度流入、空洞的回落错误等。





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签