2993|2

6

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

菜鸟问一个lm3s811串口的问题 [复制链接]

刚刚用这个板子,完全菜鸟,要想通过串口发送一串数据给arm,经过一点简单的运算,再把结果发送给pc。发送的多个数据是用空格隔开的,例如发送111   222    333过去,想让他算出他们的和666,目前找到的程序都是发送字符串,我也不知道发送到arm后它是怎么存储这些数据的,怎么才能让它自己以数组的形式存储为111,222,333三个数呢?怎么样对这些数进行操作?本人概念都比较模糊,希望哪位热心人给耐心的讲讲,或者给点例程。

最新回复

//*****************************************************************************////! 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.//!//! \return Returns the result of the conversion.////*****************************************************************************unsigned longustrtoul(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 == '\t')){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);}复制代码  详情 回复 发表于 2012-4-13 13:12
 
点赞 关注

回复
举报

2002

帖子

24

TA的资源

五彩晶圆(高级)

沙发
 
发送都是字符串,这些主要看接收方把他识别为什么,你在arm中把收到的字符串存为字符串数组,然后自己写个函数转化为长整形数字,再进行加法运算
 
 

回复

1803

帖子

0

TA的资源

五彩晶圆(高级)

板凳
 
  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.
    //!
    //! \return 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 == '\t'))
    {
    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);
    }
复制代码
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表