还是没有解决,我把主程序给发上去,希望给看看。
//----------------------------------------------------------------------------------
void main(void) {
//----------------------------------------------------------------------------------
unsigned int humi_val,temp_val;
unsigned int rh_lin,rh_true;
unsigned char error,checksum;
unsigned int i;
SCK_OUT;
PwmInit();
s_connectionreset();
for(;;)
{ error=0;
s_transstart(); //transmission start
error+=s_write_byte(STATUS_REG_W);//send command to sensor
error+=s_write_byte(STATUS_REG_D); //send value of status register
error+=s_measure((unsigned char*) &humi_val,&checksum,HUMI);
error+=s_measure((unsigned char*) &temp_val,&checksum,TEMP);
if(error!=0){
s_connectionreset();
}
else
{
rh_lin=10*humi_val+10;
rh_lin=rh_lin>>1;
//rh_true=(400*t-396400+51*t*rh-rh)/10000; 温度补偿
if(rh_lin>=1000) rh_true = 1;
else if (rh_lin<=1) rh_true =1000;
else rh_true = 1001-rh_lin;
//while(TSC0_CH0F==0);
while(TSC_TOF==0);
//TCH1 = 691;
TCH1 = rh_true;
for (i=0;i<16000;i++);
}
//-----------------------------------------------------------------------------------
__RESET_WATCHDOG(); /* feeds the dog */
}
}
|