Page 47 - MDP2022-3
P. 47
{
unsigned long sum = 0, count = 0, data1 = 0, data2 = 0;
for(j = 0; j < 20; j++)
{
sbi(PORTD, 0); //DOUT : 1
cbi(PORTD, 1); //SCK : 0
count = 0;
while((PIND & 0b00000001) == 0b00000001);
for(i = 0; i < 24; i++)
{
sbi(PORTD, 1); // SCK : 1
count = count << 1;
cbi(PORTD, 1); // SCK : 0
if((PIND & 0b00000001) == 0b00000001)
count++;
}
sbi(PORTD, 1); // SCK : 1
count = count ^ 0x800000;
cbi(PORTD, 1); // SCK : 0
sum += count;
}
data1 = sum / 20; // 20개 데이터 평균
if(offset_flag == 0)
{
offset = data1;
offset_flag = 1;
}
if(data1 > offset)
data2 = data1 - offset; // offset 제외
else
data2 = 0;
return data2;
}