diff --git a/App/electrode/electrode.c b/App/electrode/electrode.c index 2dc68fb..17043bf 100644 --- a/App/electrode/electrode.c +++ b/App/electrode/electrode.c @@ -50,3 +50,47 @@ void Phosphorus_Control_Update(void) } } +void Save_Phosphorus_Time_To_EEPROM(uint32_t run_time, uint32_t stop_time) +{ + // 保存时间参数 + Save_Float_To_EEPROM(PHOSPHORUS_RUN_TIME_ADDR, (float)run_time); + Save_Float_To_EEPROM(PHOSPHORUS_STOP_TIME_ADDR, (float)stop_time); + + // 保存标志位 + Inf_AT24C02_WriteByte(PHOSPHORUS_FLAG_ADDR, PHOSPHORUS_FLAG_VAL); +} + +void Load_Phosphorus_Time_From_EEPROM(void) +{ + uint8_t flag = Inf_AT24C02_ReadByte(PHOSPHORUS_FLAG_ADDR); + + if(flag == PHOSPHORUS_FLAG_VAL) + { + // 读取时间参数 + PHOSPHORUS_RUN_TIME = (uint32_t)Read_Float_From_EEPROM(PHOSPHORUS_RUN_TIME_ADDR); + PHOSPHORUS_STOP_TIME = (uint32_t)Read_Float_From_EEPROM(PHOSPHORUS_STOP_TIME_ADDR); + } + else + { + // 如果EEPROM中没有有效数据,使用默认值并保存 + Save_Phosphorus_Time_To_EEPROM(PHOSPHORUS_RUN_TIME, PHOSPHORUS_STOP_TIME); + } +} + + +void Phosphorus_Init(void) +{ + // 从EEPROM加载时间参数 + Load_Phosphorus_Time_From_EEPROM(); + + phosphorus_timer = 0; // 初始化计时器 + polarity_state = 0; // 初始极性状态 + Control_Phosphorus_Polarity(); // 设置初始极性 + Control_Phosphorus(1); // 初始状态开启 +} + + + + + + diff --git a/App/electrode/electrode.h b/App/electrode/electrode.h index 64a29f1..a2d4144 100644 --- a/App/electrode/electrode.h +++ b/App/electrode/electrode.h @@ -3,6 +3,12 @@ #include "main.h" #include "Driver.h" #include "Irrigation.h" +#include "eeprom.h" +#define PHOSPHORUS_RUN_TIME_ADDR 0x90 // 除磷运行时间存储地址 +#define PHOSPHORUS_STOP_TIME_ADDR 0x94 // 除磷停止时间存储地址 +#define PHOSPHORUS_FLAG_ADDR 0x98 // 除磷标志地址 +#define PHOSPHORUS_FLAG_VAL 0xB7 // 除磷标志值 + extern uint8_t phosphorus_running; // 除磷运行状态 extern uint8_t polarity_state; // 极性状态:0-正常,1-反转 extern uint32_t phosphorus_timer; // 运行时间计数器(分钟) @@ -17,6 +23,9 @@ void Control_Phosphorus_Polarity(void); void Phosphorus_Control_Update(void); +void Phosphorus_Init(void); +void Save_Phosphorus_Time_To_EEPROM(uint32_t run_time, uint32_t stop_time); + #endif diff --git a/Core/Src/main.c b/Core/Src/main.c index 58a182f..339bfc9 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -155,7 +155,7 @@ int main(void) // Clear_EEPROM_All(); Ozone_Init(); - + Phosphorus_Init(); printf("Initializing ozone control...\n"); //Inf_AT24C02_Init(); @@ -178,7 +178,7 @@ int main(void) // Control_Fan2(1); // Print_Temperature(data1); // 闂傚倷绀侀幉锟犲垂閸忓吋鍙忛柕鍫濐槸濮规煡鏌i弮鍌氬付缂佲偓閸愵喗鐓曟繛鎴炵懄缂嶆垿鏌涢弬璇插姎闂囧鏌涜箛姘汗闁绘搩鍨伴埞鎴︽倷閸欏鏋犻梺璇″枙缁瑩宕洪垾鏂ョ倳婵犳洘鎴縟ata[1] Inf_EC800_ReadData(); - // Direct_Mode_Control(); + // Direct_Mode_Control(); Check_4G_Connection(); @@ -210,7 +210,7 @@ int main(void) if(UART4_RX_STA & 0x8000) { - Data_Processing(); + Data_Processing(); } diff --git a/Inf/Inf_4G.c b/Inf/Inf_4G.c index f6b9bf5..ac9f83b 100644 --- a/Inf/Inf_4G.c +++ b/Inf/Inf_4G.c @@ -520,12 +520,16 @@ void Inf_EC800_ReadData(void) else if (sscanf(jsonStr, "{\"X51\":%d}", &value) == 1) { PHOSPHORUS_RUN_TIME=value; + phosphorus_timer = 0; // üʱ + Save_Phosphorus_Time_To_EEPROM(PHOSPHORUS_RUN_TIME, PHOSPHORUS_STOP_TIME); // 浽EEPROM // printf("óʱΪ%d\n", value); } // óֹͣʱ䣨X34 else if (sscanf(jsonStr, "{\"X52\":%d}", &value) == 1) { PHOSPHORUS_STOP_TIME=value; + phosphorus_timer = 0; // üʱ + Save_Phosphorus_Time_To_EEPROM(PHOSPHORUS_RUN_TIME, PHOSPHORUS_STOP_TIME); // 浽EEPROM // printf("óֹͣʱΪ%d\n", value); } // Զ̿ƴ diff --git a/MDK-ARM/.vscode/uv4.log b/MDK-ARM/.vscode/uv4.log index 6ec804d..63cbcf3 100644 --- a/MDK-ARM/.vscode/uv4.log +++ b/MDK-ARM/.vscode/uv4.log @@ -1,4 +1,20 @@ *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'E:\MDK536\ARM\ARMCC\Bin' Build target '4G_test' +compiling Ozone.c... +compiling Driver.c... +compiling Inf_4G.c... +compiling stm32f4xx_it.c... +compiling main.c... +compiling Irrigation.c... +compiling wendu.c... +compiling shuiliang.c... +compiling HLW8032.c... +compiling guangshi.c... +compiling electrode.c... +compiling Save_Time.c... +compiling paini.c... +linking... +Program Size: Code=35144 RO-data=896 RW-data=572 ZI-data=4092 +FromELF: creating hex file... "4G_test\4G_test.axf" - 0 Error(s), 0 Warning(s). -Build Time Elapsed: 00:00:03 +Build Time Elapsed: 00:00:34 diff --git a/MDK-ARM/.vscode/uv4.log.lock b/MDK-ARM/.vscode/uv4.log.lock index 3a53cde..6c2c2ee 100644 --- a/MDK-ARM/.vscode/uv4.log.lock +++ b/MDK-ARM/.vscode/uv4.log.lock @@ -1 +1 @@ -2025/5/20 15:04:57 \ No newline at end of file +2025/5/21 13:19:43 \ No newline at end of file diff --git a/MDK-ARM/4G_test/4G_test.axf b/MDK-ARM/4G_test/4G_test.axf index 9921dd9..558030a 100644 Binary files a/MDK-ARM/4G_test/4G_test.axf and b/MDK-ARM/4G_test/4G_test.axf differ diff --git a/MDK-ARM/4G_test/4G_test.build_log.htm b/MDK-ARM/4G_test/4G_test.build_log.htm index 62702a5..95f6d45 100644 --- a/MDK-ARM/4G_test/4G_test.build_log.htm +++ b/MDK-ARM/4G_test/4G_test.build_log.htm @@ -27,6 +27,22 @@ Project File Date: 04/22/2025