Browse Source

ahtx0温湿度到系统温湿度

master
忱 沈 3 weeks ago
parent
commit
823153c8ea
  1. 8
      applications/PLC_link.c
  2. 3
      applications/data/Variable.c
  3. 10
      applications/drv/drv_aht20.c

8
applications/PLC_link.c

@ -27,6 +27,8 @@ static const mb_backend_param_t mb_bkd_prm = {
.rtu.lvl = 0 //控制发送电平
};
extern unsigned int sys_temperature;
extern unsigned int sys_humidity;
static void mb_plc_read_regs(mb_inst_t *hinst)
{
@ -37,9 +39,13 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
}
u16 regs[64];
regs[0]=sys_temperature;
regs[1]=sys_humidity;
int addr = 7000;
int nb = 10;
int total = mb_read_input_regs(hinst, addr, nb, regs);
int total = mb_write_regs(hinst, addr, nb, regs);
if (total <= 0)
{
return;

3
applications/data/Variable.c

@ -3,6 +3,9 @@
// ===== 实际定义 =====
unsigned int sys_temperature;
unsigned int sys_humidity;
// 动态数据缓冲区(初始化为 NULL,后续分配)
char *DATA_dat;
char DATA_machins[3];

10
applications/drv/drv_aht20.c

@ -134,7 +134,9 @@ static void aht20_parse_data(const rt_uint8_t raw[6], rt_int32_t *temp, rt_int32
static void aht20_thread_entry(void *parameter)
{
rt_uint8_t raw_data[6];
rt_int32_t temperature, humidity;
extern unsigned int sys_temperature;
extern unsigned int sys_humidity;
while (1)
{
@ -162,11 +164,7 @@ static void aht20_thread_entry(void *parameter)
continue;
}
aht20_parse_data(raw_data, &temperature, &humidity);
LOG_I("Temp: %d.%dC, Humidity: %d.%dRH",
temperature / 10, temperature % 10,
humidity / 10, humidity % 10);
aht20_parse_data(raw_data, &sys_temperature, &sys_humidity);
rt_thread_mdelay(5000); // 每 2 秒读取一次
}

Loading…
Cancel
Save