Files
CHJ/user/Device/HAFBLF0750C4AX5.c
2026-03-20 21:19:04 +08:00

69 lines
1.3 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "../main/SystemInclude.h"
// 读取传感器数据
u16 AirflowSensor_Read(void)
{
u8 raw_data[2] = {0};
SI2C_Start();
// 发送读取命令(地址 + 读模式)
SI2C_Write((HAF_ADR << 1) | 0x01);
// 连续读取2字节数据
// 数据格式:[流量高8位, 流量低8位]
raw_data[0] = SI2C_Read();
SI2C_Ack(); // 发送ACK继续读取
raw_data[1] = SI2C_Read();
SI2C_NoAck();// 最后一个字节发送NACK
SI2C_Stop();
// 合并流量数据16位
u16 flow_raw =((raw_data[0] << 8) | raw_data[1]) ;
return flow_raw ;
}
// 批量读取多次取平均值
u16 AirflowSensor_ReadAverage(u8 count)
{
u8 valid_count = 0;
u32 total_flow = 0;
if (count <= 0) return 0;
for (uint8_t i = 0; i < count; i++)
{
total_flow += AirflowSensor_Read();
valid_count++;
delay_ms(10);
}
if (valid_count > 0) {
total_flow= total_flow / valid_count;
}
return total_flow;
}
// 转换成SCCM
#define MaximumFlow 750 //SCCM
float Get_AirflowSensor_SCCM(void)
{
u16 total_flow = 0;
float slpm_flow;
total_flow = AirflowSensor_ReadAverage(10);//读取连续转换10次的平均值
if(total_flow > 8192)slpm_flow = (total_flow-8192)*MaximumFlow;
else slpm_flow = (total_flow+8192)*MaximumFlow;
slpm_flow = slpm_flow/ 8192;
return slpm_flow;
}