void main(void)
{
unsigned int OverCounter = 0;
unsigned char ptemp;
bit OverFlg = 0;
unsigned int temp,ppress = 0;
float press;
while(1)
{
getdata=Adc0832(0);
if(14<getdata<243) //当压力值介于15kpa到115kpa之间时,遵循线性变换
{
int vary=getdata; //y=(115-15)/(243-13)*X+15kpa
press=((10.0/23.0)*vary)+9.3; //测试时补偿值为9.3
temp=(int)(press*10); //放大10倍,便于后面的计算
if(temp != ppress)
{
ppress = temp;
OverFlg = 1;
}
dispbuf[3]=temp/1000; //取压力值百位
dispbuf[2]=(temp%1000)/100; //取压力值十位
dispbuf[1]=((temp%1000)%100)/10; //取压力值个位
dispbuf[0]=((temp%1000)%100)%10; //取压力值十分位
display();
if (temp > 100)
{
if(OverFlg == 1) //如果是新的一辆车通过
{
OverCounter++;
WIICByte(W24C04ADD,0x01,(OverCounter/0xff)); //低位
WIICByte(W24C04ADD,0x02,(OverCounter%0xff)); //高位
// ptemp = printf("%f\n",OverCounter);
OverFlg = 0; //清除标志
}
}
}
}
}
是个小白,不能再白了,请大佬帮看看,讲解下代码含义,谢谢啦
|