함수

2014-03-19 4 views
0

제가함수

EEPROM

저장 배열은 어드레스 54 개, 요소 0' 주소 '까지 {0,0,0,0,1,1,1} ...로 시작했다 53 '과 나는 값을 교차 체크하고 모든 것이 좋다.

하지만 '검색 기능'을 사용할 때 0 번째 주소에서 검색 할 때 '0'을 인수로 전달했습니다.

서명 숯불 됨 (숯 CURRENT_TIME)

    { 
         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'th 소자 영이 아닌 보낸 후 갖는다.

하지만 항상 53을 반환합니다.

왜 그렇게됩니까?

나는 c18 컴파일러를 사용합니다. 논리에 실수가 있다면 저를 바로 잡아주십시오.

감사

답변

1
는 휴식 만 while 루프에서 휴식 위의 코드에서

때문에, x는 0이 아닌 경우 while 루프가 중단됩니다 그러나 대한 루프가 증가하고 계속 싸는한다 어쨌든 loopcnt가 54 (53 이상) 일 때 addr이 항상 53이 될 때만 중단됩니다.