static unsigned char __softReset(void) { unsigned char error = 0; __resetConnection(); //reset communication __startTransfer(); error += __writeByte(0x1e); //send RESET-command to sensor return error; //error=1 in case of no response form the sensor }
//---------------------------------------------------------------------------------- // 返回值单位0.01摄氏度 static int __readTemperature(void) { unsigned int i; int temp; __resetConnection(); __writeByte(0x03); vTaskDelay(configTICK_RATE_HZ * 320 / 1000); for (i = 0; i < 500; ++i) { if (__readDataBit() == 0) { break; } vTaskDelay(configTICK_RATE_HZ / 10); } temp = __readData(); //会得到origin_temp temp = temp - 4000; //calc. temperature from ticks to [%C] //t=d1+d2*SOt if (temp > 6000) { temp = 6000; //cut if the value is outside of } if (temp < -900) { temp = -900; //the physical possible range } return temp; }
int writeByte_nonblocking(char byte, uint8_t usartn) { if (canWrite(usartn)) { __writeByte(byte, usartn); return 0; } return -1; }
//---------------------------------------------------------------------------------- static int __readHumidity(int temp) { unsigned int i; int humi; __resetConnection(); __writeByte(0x05); vTaskDelay(configTICK_RATE_HZ * 400 / 1000); for (i = 0; i < 500; ++i) { if (__readDataBit() == 0) { break; } vTaskDelay(configTICK_RATE_HZ / 10); } humi = __readData(); // temp_c = 0.01 * origin_temp - 40; // rh_lin = humi*0.0405 - 0.0000028*humi*humi - 4.0; // rh_true = rh_lin + (temp_c-25)*(0.01+0.00008*humi); // rh_true = (rh_lin * 100) + (temp - 2500) * (0.01 + 0.00008 * humi); // *100 // rh_true = (rh_lin * 100*100000) + (temp - 2500) * (1000 + 8 * humi); // *100*100000 // rh_true = ((humi * 0.0405 - 0.0000028 * humi * humi - 4.0) * 100000000) + (temp - 2500) * (1000 + 8 * humi); // *100*100000 // rh_true = ((humi * 405000 - 28 * humi * humi - 40000000)) + (temp - 2500) * (1000 + 8 * humi); // *100*100000 // rh_true = rh_true / (1000 * 10000); humi = ((humi * 405000 - 28 * humi * humi - 40000000)) + (temp - 2500) * (1000 + 8 * humi); // *100*100000 humi = humi / (100 * 10000); if (humi > 999) { humi = 999; } if (humi < 1) { humi = 1; } return humi; }