菜鸟问一个lm3s811串口的问题

2019-03-24 14:36发布

刚刚用这个板子,完全菜鸟,要想通过串口发送一串数据给arm,经过一点简单的运算,再把结果发送给pc。发送的多个数据是用空格隔开的,例如发送111   222    333过去,想让他算出他们的和666,目前找到的程序都是发送字符串,我也不知道发送到arm后它是怎么存储这些数据的,怎么才能让它自己以数组的形式存储为111,222,333三个数呢?怎么样对这些数进行操作?本人概念都比较模糊,希望哪位热心人给耐心的讲讲,或者给点例程。 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
shower.xu
1楼-- · 2019-03-24 20:50
 精彩回答 2  元偷偷看……
Study_Stellaris
2楼-- · 2019-03-25 00:44
< :TI_MSP430_内容页_SA7 -->
  1. //*****************************************************************************
    //
    //! Converts a string into its numeric equivalent.
    //!
    //! param pcStr is a pointer to the string containing the integer.
    //! param ppcStrRet is a pointer that will be set to the first character past
    //! the integer in the string.
    //! param iBase is the radix to use for the conversion; can be zero to
    //! auto-select the radix or between 2 and 16 to explicitly specify the radix.
    //!
    //! This function is very similar to the C library <tt>strtoul()</tt> function.
    //! It scans a string for the first token (that is, non-white space) and
    //! converts the value at that location in the string into an integer value.
    //!
    //! eturn Returns the result of the conversion.
    //
    //*****************************************************************************
    unsigned long
    ustrtoul(const char *pcStr, const char **ppcStrRet, int iBase)
    {
    unsigned long ulRet, ulDigit, ulNeg, ulValid;
    const char *pcPtr;

    //
    // Check the arguments.
    //
    ASSERT(pcStr);
    ASSERT((iBase == 0) || ((iBase > 1) && (iBase <= 16)));

    //
    // Initially, the result is zero.
    //
    ulRet = 0;
    ulNeg = 0;
    ulValid = 0;

    //
    // Skip past any leading white space.
    //
    pcPtr = pcStr;
    while((*pcPtr == ' ') || (*pcPtr == ' '))
    {
    pcPtr++;
    }

    //
    // Take a leading + or - from the value.
    //
    if(*pcPtr == '-')
    {
    ulNeg = 1;
    pcPtr++;
    }
    else if(*pcPtr == '+')
    {
    pcPtr++;
    }

    //
    // See if the radix was not specified, or is 16, and the value starts with
    // "0x" or "0X" (to indicate a hex value).
    //
    if(((iBase == 0) || (iBase == 16)) && (*pcPtr == '0') &&
    ((pcPtr[1] == 'x') || (pcPtr[1] == 'X')))
    {
    //
    // Skip the leading "0x".
    //
    pcPtr += 2;

    //
    // Set the radix to 16.
    //
    iBase = 16;
    }

    //
    // See if the radix was not specified.
    //
    if(iBase == 0)
    {
    //
    // See if the value starts with "0".
    //
    if(*pcPtr == '0')
    {
    //
    // Values that start with "0" are assumed to be radix 8.
    //
    iBase = 8;
    }
    else
    {
    //
    // Otherwise, the values are assumed to be radix 10.
    //
    iBase = 10;
    }
    }

    //
    // Loop while there are more valid digits to consume.
    //
    while(1)
    {
    //
    // See if this character is a number.
    //
    if((*pcPtr >= '0') && (*pcPtr <= '9'))
    {
    //
    // Convert the character to its integer equivalent.
    //
    ulDigit = *pcPtr++ - '0';
    }

    //
    // Otherwise, see if this character is an upper case letter.
    //
    else if((*pcPtr >= 'A') && (*pcPtr <= 'Z'))
    {
    //
    // Convert the character to its integer equivalent.
    //
    ulDigit = *pcPtr++ - 'A' + 10;
    }

    //
    // Otherwise, see if this character is a lower case letter.
    //
    else if((*pcPtr >= 'a') && (*pcPtr <= 'z'))
    {
    //
    // Convert the character to its integer equivalent.
    //
    ulDigit = *pcPtr++ - 'a' + 10;
    }

    //
    // Otherwise, this is not a valid character.
    //
    else
    {
    //
    // Stop converting this value.
    //
    break;
    }

    //
    // See if this digit is valid for the chosen radix.
    //
    if(ulDigit >= iBase)
    {
    //
    // Since this was not a valid digit, move the pointer back to the
    // character that therefore should not have been consumed.
    //
    pcPtr--;

    //
    // Stop converting this value.
    //
    break;
    }

    //
    // Add this digit to the converted value.
    //
    ulRet *= iBase;
    ulRet += ulDigit;

    //
    // Since a digit has been added, this is now a valid result.
    //
    ulValid = 1;
    }

    //
    // Set the return string pointer to the first character not consumed.
    //
    if(ppcStrRet)
    {
    *ppcStrRet = ulValid ? pcPtr : pcStr;
    }

    //
    // Return the converted value.
    //
    return(ulNeg ? (0 - ulRet) : ulRet);
    }
复制代码

一周热门 更多>

相关问题

    相关文章