unsigned char humih1,humil1,temph1,templ1;
unsigned int r_temp,t_temp;
void sension_single_0()
{
unsigned int i,j,k,t[100],m=0;
uint8 data[10];
uint8 temp[20];
uint8 check=0;
Data_Write(0);
CyDelayUs(1000);
Data_Write(1);
Data_SetDriveMode(Data_DM_RES_UPDWN);
t[0]=0;
while((Data_Read())&&(t[0]<500))
{
t[0]++;
}
t[1]=0;
while((!(Data_Read()))&&(t[1]<500))//low 80us
{
t[1]++;
}
t[2]=0;
while((Data_Read())&&(t[2]<500))//high 80us
{
t[2]++;
}
k=0;
data[k]=0;
j=0;
for(i=0;i<40;i++)//读取数据
{
t[3+2*i]=0;
while((!(Data_Read()))&&(t[3+2*i]<500))//low 50us
{
t[3+2*i]++;
}
t[4+2*i]=0;
while((Data_Read())&&(t[4+2*i]<500))//high 80us
{
t[4+2*i]++;
}
if(t[4+2*i]>10)
{
data[k] |= (0x01<<(7-j));
}
j++;
if(j==8)
{
j=0;
k++;
data[k]=0;
}
}
Data_SetDriveMode( Data_DM_STRONG );
Data_Write(1);
check=(data[0]+data[1]+data[2]+data[3]);
if(data[4]==check)
{
r_temp=data[0];
r_temp<<=8;
r_temp+=data[1];
t_temp=data[2];
t_temp<<=8;
t_temp+=data[3];
}
else
{
r_temp=0;
t_temp=0;
}
} |