修改,使temp为有用结果
时间: 2024-02-25 13:57:04 浏览: 61
好的,根据你的需求,我稍微修改了一下代码,修改后的函数如下所示:
```
void ReadPms5003(void)
{
uint16_t buffer_len;
unsigned int pm1_0_cf, pm2_5_cf, pm10_cf, pm1_0, pm2_5, pm10, count0_3nm, pcount0_5nm, count1_0nm, count2_5nm, count5_0nm, count10nm;
buffer_len = (uint16_t)((PM_Sensor_RxBuffer[2] << 8) | PM_Sensor_RxBuffer[3]);
if(buffer_len == 28) //PMS1003/5003
{
PM_Sensor_Data.Buffer_Len = 36;
pm1_0_cf = (uint16_t)((PM_Sensor_RxBuffer[4]<<8) | PM_Sensor_RxBuffer[5]);
pm2_5_cf = (uint16_t)((PM_Sensor_RxBuffer[6]<<8) | PM_Sensor_RxBuffer[7]);
pm10_cf = (uint16_t)((PM_Sensor_RxBuffer[8]<<8) | PM_Sensor_RxBuffer[9]);
pm1_0 = (uint16_t)((PM_Sensor_RxBuffer[10]<<8) | PM_Sensor_RxBuffer[11]);
pm2_5 = (uint16_t)((PM_Sensor_RxBuffer[12]<<8) | PM_Sensor_RxBuffer[13]);
pm10 = (uint16_t)((PM_Sensor_RxBuffer[14]<<8) | PM_Sensor_RxBuffer[15]);
count0_3nm = (uint16_t)((PM_Sensor_RxBuffer[16]<<8) | PM_Sensor_RxBuffer[17]);
pcount0_5nm = (uint16_t)((PM_Sensor_RxBuffer[18]<<8) | PM_Sensor_RxBuffer[19]);
count1_0nm = (uint16_t)((PM_Sensor_RxBuffer[20]<<8) | PM_Sensor_RxBuffer[21]);
count2_5nm = (uint16_t)((PM_Sensor_RxBuffer[22]<<8) | PM_Sensor_RxBuffer[23]);
count5_0nm = (uint16_t)((PM_Sensor_RxBuffer[24]<<8) | PM_Sensor_RxBuffer[25]);
count10nm = (uint16_t)((PM_Sensor_RxBuffer[26]<<8) | PM_Sensor_RxBuffer[27]);
}
// 在这里对读取到的数据进行处理,可以将其打印出来或者保存到文件中等等
// 下面是一个简单的示例:将 PM2.5 的浓度值打印到串口终端
printf("PM2.5 concentration is: %d\n", pm2_5);
}
```
修改后的函数中,我将返回值类型从 unsigned char 修改为 void,因为该函数的主要作用是对读取到的数据进行处理,而不是返回某个具体的数值。同时,我在函数中添加了一些注释,以便理解。
你可以根据具体的需求,对函数中的处理部分进行修改,以实现相应的功能。
阅读全文