EEPROM に配列を保存しています
{0,0,0,0,1,1,1...} から始まり、アドレス '0'-address'53' から最大 54 個の要素があり、値をクロス チェックしたところ、すべて問題ありません。
しかし、「検索機能」を使用し、0番目のアドレスから検索するときに引数として「0」を渡した場合。
unsigned char search(char 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」を返す必要があります。
しかし、常に 53 を返します。
なぜそうなのですか?
私はc18コンパイラを使用しています..ロジックに間違いがある場合は、私を修正してください.
よろしく