系统时间,环境温度湿度功能

This commit is contained in:
sc committed 2025-12-28 21:21:47 +08:00
1 parent 823153c8ea
commit 0dfe8ddb1c
4 files changed
+28 -9

No files matched your search

+9 -4
View File
@@ -27,8 +27,9 @@ static const mb_backend_param_t mb_bkd_prm = {
.rtu.lvl = 0 //控制发送电平
};
extern unsigned int sys_temperature;
extern unsigned int sys_humidity;
extern rt_int32_t sys_temperature;
extern rt_int32_t sys_humidity;
extern unsigned char sys_time[6];
static void mb_plc_read_regs(mb_inst_t *hinst)
{
@@ -40,8 +41,12 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
u16 regs[64];
regs[0]=sys_temperature;
regs[1]=sys_humidity;
regs[0]=sys_temperature;//系统温度
regs[1]=sys_humidity;//系统湿度
for(int8_t i=0;i<=5;i++)//系统时间
{
regs[i+2] = sys_time[i];
}
int addr = 7000;
int nb = 10;
+5 -2
View File
@@ -2,9 +2,12 @@
#include <string.h>
// ===== 实际定义 =====
//系统信息变量
rt_int32_t sys_temperature;//主机环境温度
rt_int32_t sys_humidity;//主机环境湿度
unsigned char sys_time[6];//系统时间
unsigned int sys_run_time;//运行时间
unsigned int sys_temperature;
unsigned int sys_humidity;
// 动态数据缓冲区(初始化为 NULL,后续分配)
char *DATA_dat;
+2 -2
View File
@@ -135,8 +135,8 @@ static void aht20_thread_entry(void *parameter)
{
rt_uint8_t raw_data[6];
extern unsigned int sys_temperature;
extern unsigned int sys_humidity;
extern rt_int32_t sys_temperature;
extern rt_int32_t sys_humidity;
while (1)
{
+12 -1
View File
@@ -141,6 +141,9 @@ static void ds1307_read_time(void)
}
/* Software thread to maintain local time estimation */
time_t now;
struct tm *p_tm;
extern unsigned char sys_time[6];
static void auto_update_current_datatime(void *parameter)
{
uint32_t count = 0;
@@ -154,6 +157,14 @@ static void auto_update_current_datatime(void *parameter)
ds1307_read_time();
count = 0;
}
time(&now); // 获取当前日历时间(秒,自 1970-01-01 00:00:00 UTC)
p_tm = localtime(&now); // 转换为本地时间结构
sys_time[5]= p_tm->tm_year - 100;
sys_time[4]= p_tm->tm_mon + 1;
sys_time[3]= p_tm->tm_mday;
sys_time[2]= p_tm->tm_hour;
sys_time[1]= p_tm->tm_min;
sys_time[0]= p_tm->tm_sec;;
}
}
@@ -210,7 +221,7 @@ static int rt_hw_ds1307_rtc_init(void)
ds1307_read_time();
ds1307.thd_soft_update_sec = rt_thread_create("ds1307",auto_update_current_datatime,RT_NULL,256, 20, 5);
ds1307.thd_soft_update_sec = rt_thread_create("ds1307",auto_update_current_datatime,RT_NULL,512, 20, 5);
if (ds1307.thd_soft_update_sec)
{
rt_thread_startup(ds1307.thd_soft_update_sec);