首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >eeprom搜索功能

eeprom搜索功能
EN

Stack Overflow用户
提问于 2014-03-19 15:13:51
回答 1查看 98关注 0票数 0

我在EEPROM中存储了一个数组

从地址‘0’到地址‘53’的{0,0,0,1,1.}最多54个元素开始,我已经交叉检查了值,一切都很好。

但是,当我使用‘搜索函数’,并且我已经传递'0‘作为参数,因为它搜索从第0地址。

无符号字符搜索( char current_time)

代码语言:javascript
复制
                    {
                        unsigned int    loopcnt = 0;
                        unsigned int   add ;
                        unsigned char   addr = 0;          //We will store start address of 1's here
                        unsigned char lastAddr =current_time;
                                            unsigned int x;
                    add = 0;
                              //If lastAddr is already overflowing, reset it
            if(lastAddr >= 53)
            {
                    lastAddr = 0;
                    addr=53;
                    return(addr);
            }

                    for(loopcnt = lastAddr; loopcnt < 54; loopcnt++)
                {

                    addr = loopcnt;
                                    x=eeread(add);
                                    //This is start location of our scanning
                                        while(x!= 0)
                            {
                                        x=eeread(add);
                    loopcnt++;
                                             add++;
                    //Count the 1's we got!
                    if(loopcnt==53)
                    {
                        addr=53;
                        break;
                    }
                }


                }

                    return (addr);

            }

但是它必须返回'4‘作为值,因为’4‘之后的元素是非零的。

但它总是返回53。

为什么是那样的?

我在使用c18 compiler..If,逻辑上有任何错误,请纠正我。

问候

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-19 16:29:57

在上面的代码中,中断只会从while循环中中断,因此,while循环在x为非零时会中断,但是包围它的for-循环无论如何都会增加并继续,只有在循环为54 (高于53)时才会中断,此时addr始终是53。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22510235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档