Cypress技术论坛
直播中

李秀华

7年用户 134经验值
私信 关注
[问答]

从程序PSOC5返回的bug

似乎柏树科技的支持已经不复存在了。哦,天哪!
这是我的问题:我的小程序,将一个二进制数字转换为ASCII字符串,并返回字符串的字符数。它包括领先的消零如果需要(cfixeddigitcount = 0)或固定长度的消息带前导零。看起来像这样。
cbinarytoascii uint8(uint16 ISOURCE,uint8 sconversion [],uint8 cfixeddigitcount)
{//返回字符串中的字符数
/cFixDeDigigt允许前导零
utiN C点,CI;
uTIN 16;
C点=0;
当(伊索)!= 0)
{
IRMAMEDER = ISURCE % 10;
转换[cPosi]=(uTIn8)(iReMeNead)0x30;
C点++;
iSouCE=10;
}
如果(cFixDigDigig计数)
{//仅当非零时,否则引导零闪烁
如果(C点& lt;(cFixDigDigig计数))
{
对于(CI=0;CI & lt;(CcIdDigDigigalCcPoT);Ci++)
{
sconversion [ CPoint ] = '0';
CPoint + +;
}
}
}
返回CPoint;
}
到目前为止,它似乎已经奏效了。该计划自我测试了它长大了不少,但我还没有看到的问题。
我只是用它在一个新的模块如下
CJ = cbinarytoascii(iretrievedparameter,casciiresult,0);
CJ是一个地方的卡片,casciiresult是uint8阵列5
当我走过cbinarytoascii,或通过它与断点,出现CPoint的号码是正确的,在这种特定的情况下。但在调用模块CJ值0x1a。如果我改变CJ从局部变量的一个全球性的,它的正确性。
不知道我做错了什么,或是在编译错误?
编译器的细节
PSoC Creator(4.2.0.641 4.2)
                    
                    
以上来自于百度翻译

               
                                                                                      以下为原文
                                            It seems that Cypress Tech Support is no more. Oh dear!
Here is my problem: I have small procedure that converts a binary number to an ASCII string, and returns the number of characters in that string. It includes leading zero blanking if desired (cFixedDigitCount=0) or a fixed length message with leading zeros. It looks like this.

uint8 cBinaryToAscii (uint16 iSource, uint8 sConversion[], uint8 cFixedDigitCount)
{//return the number of characters in the string
//cFixedDigitCount to allow for leading zero   
    uint8 cPoint,cI;
    uint16 iRemainder;
    cPoint=0;
    while (iSource!=0)
    {
        iRemainder=iSource%10;
        sConversion[cPoint]=(uint8)(iRemainder) | 0x30;
        cPoint++;
        iSource/=10;
    }
    if (cFixedDigitCount)
    {//only if non-zero, else leading zero blnking
        if (cPoint<(cFixedDigitCount))
        {
            for (cI=0;cI<(cFixedDigitCount-cPoint);cI++)
            {
                sConversion[cPoint]='0';
                cPoint++;
            }
        }
    }
    return cPoint;
}

Up till now it seems to have worked. The program has grown a lot since I tested it out, but I have not seen problems.

I have just used it in a new module as follows
cJ=cBinaryToAscii(iRetrievedParameter,cASCIIResult,0);
cJ is a local uint8, cASCIIResult is a 5 uint8 array

When I step through the cBinaryToASCII, or run through it with a breakpoint, the number appearing for cPoint is correct, 4 in this specific case. But in the calling module cJ has a value of 0x1A. If I change cJ from a local variable to a global one, it works correctly.

Any idea what I am doing wrong, or is there a bug in the compiler?
Compiler details
PSoC Creator 4.2 (4.2.0.641)

回帖(4)

李秀华

2018-8-20 06:06:57
看来,问题不在回归,但与变量的命名为“CJ”。我用CJ到处为局部变量的一个指标,它不似乎是正确的创建和初始化。
                    
                    
以上来自于百度翻译

               
                                                                                      以下为原文
                                            It seems that the problem is not in the return, but with the variable named "cJ". I use cJ as an index everywhere as a local variable, and it doesn't appear to be creating/initialising it correctly.
举报

李秀华

2018-8-20 06:23:24
引用: dewars12 发表于 2018-8-20 06:06
看来,问题不在回归,但与变量的命名为“CJ”。我用CJ到处为局部变量的一个指标,它不似乎是正确的创建和初始化。
                    
                    以上来自于百度翻译

好啊。所以问题是代码的优化,虽然我的优化级别设置调试。遵循“CJ =…”的路线。
是一个用词作为一个计数器和CJ为起始地址的声明,但我让他们倒。看来,这个错误产生的代码,没有分配正确的价值来CJ。
                    
                    
以上来自于百度翻译

               
                                                                                      以下为原文
                                            OK. SO the problem is with the optimization of the code, even though my optimization level is set to Debug. The line that followed "cJ=..."
was a for statement using cI as a counter and cJ as the starting address, but I got them inverted. Seems that this error produced code that did not assign the correct value to cJ.
举报

王琳

2018-8-20 06:29:19
引用: dewars12 发表于 2018-8-20 06:23
好啊。所以问题是代码的优化,虽然我的优化级别设置调试。遵循“CJ =…”的路线。
是一个用词作为一个计数器和CJ为起始地址的声明,但我让他们倒。看来,这个错误产生的代码,没有分配正确的价值来CJ。
                    

尝试将优化级别设置为“无”
鲍勃
                    
                    
以上来自于百度翻译

               
                                                                                      以下为原文
                                            Try setting optimization level to "none"
 
Bob
举报

李秀华

2018-8-20 06:45:08
引用: ncmza 发表于 2018-8-20 06:29
尝试将优化级别设置为“无”
鲍勃
                    

鲍勃
谢谢。我记得读到“调试”是在同一水平作为“无”。我会努力的,虽然现在的问题是治好了,我不知道如何证明。
                    
                    
以上来自于百度翻译

               
                                                                                      以下为原文
                                            Bob
 
Thanks. I seem to remember reading that "debug" was at the same level as "none". I will try it, although since the problem is now cured, I am not sure how to prove it.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分