📄 process.c
字号:
#include "sfr_r82b.h"
#include "main_define.h"
#include "disp_definel.h"
//#pragma SECTION program pro_3
unsigned char rinse_led;
unsigned char display_number;
unsigned char left_time;
void soak_1(void);
void soak_2(void);
void soak_3(void);
/********************************************************************************
Inlet has 3 kinds of condition:
1, Normal;
2, During running;
3, Cycle ON/OFF;
4, Softener inlet: A, the inlet time value in time table is set higher than 2m
B, need take care if softener inlet are not
finished while inlet already finished
*********************************************************************************/
void inlet(unsigned char inlet_time, unsigned char cycle, unsigned char level)
{
static unsigned char cycle_buff = 0;
unsigned char i;
signed char j;
if (process_left_time == 0) /* 过程剩余时间为0时,重置过程剩余时间 */
process_left_time = inlet_2m_buff;
if ((level)&&(inlet_time)) /* 当主调函数传递的水位和进水时间参数为真时,正常进水 */
{
if (water_full_flag != 1)
{
// Inlet_OPT = 0;
// Inlet_OPT_1 = 0;
output_buff |= INLET; /* 打开进水阀门 */
}
j = inlet_time;
if (j > INLET_SET_TIME) /* 当数据表进水时间大于默认时间时,表明是最后一次蓄水漂洗 */
{
if (softener_flag != 1); /* 判定打开软化剂进水 */
{
// SOF_Inlet_OPT = 0;
// SOF_Inlet_OPT_1 = 0;
output_buff |= SOFNER;
}
if (inlet_10s_buff <= 0)
{
// SOF_Inlet_OPT = 1;
// SOF_Inlet_OPT_1 = 1;
output_buff &= (~SOFNER); /* 关闭软化剂进水 */
inlet_10s_buff = SOFTENER_INLET_TIME;
softener_flag = 1;
if (water_full_flag == 1) /* 软化剂注入完毕如果水满,则进入下一个过程 */
{
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
return;
}
}
}
if (inlet_10s_buff > 0) /* 进水过程所需计数变量计时 */
inlet_10s_buff --;
if (inlet_20m_buff > 0)
inlet_20m_buff --;
if (inlet_2m_buff > 0)
{
inlet_2m_buff --;
process_left_time --; /* 过程剩余时间计时 */
}
if (inlet_20m_buff == 0) /* 金水超时判定及处理 */
{
// Inlet_OPT = 1;
// Inlet_OPT_1 = 1;
output_buff &= (~INLET);
inlet_20m_buff = INLET_ERR_TIME;
inlet_2m_buff = INLET_SET_TIME;
inlet_10s_buff = SOFTENER_INLET_TIME;
process_left_time = inlet_2m_buff;
err_buff = INLET_OVTIME_ERR;
return;
}
if (water_level_buff >= 4) /* 当设定水位大于4水位的进水处理 */
{
if (water_buff >= 3) /* 当水位超过3水位,停止2m变量计时 */
{
// inlet_20m_buff = INLET_ERR_TIME;
// inlet_2m_buff = INLET_SET_TIME;
// inlet_20m_buff = 0;
inlet_2m_buff = 0;
if (water_buff == water_level_buff)
{
water_full_flag = 1;
// Inlet_OPT = 1;
// Inlet_OPT_1 = 1;
output_buff &= (~INLET);
if ((j == INLET_SET_TIME)||(j == 40)) /* 正常进水结束处理 */
{
inlet_20m_buff = INLET_ERR_TIME;
inlet_2m_buff = INLET_SET_TIME;
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
return;
}
else if ((j > INLET_SET_TIME)&&(softener_flag == 1)) /* 最后一次进水结束处理 */
{
inlet_20m_buff = INLET_ERR_TIME;
inlet_2m_buff = INLET_SET_TIME;
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
return;
}
}
}
}
if (water_buff == water_level_buff) /* 水位设定小于4水位时的处理 */
{
// inlet_20m_buff = INLET_ERR_TIME;
// inlet_2m_buff = INLET_SET_TIME;
// inlet_20m_buff = 0;
inlet_2m_buff = 0;
// Inlet_OPT = 1;
// Inlet_OPT_1 = 1;
output_buff &= (~INLET);
water_full_flag = 1;
if ((j == INLET_SET_TIME)||(j == 40)) /* 正常进水结束处理 */
{
inlet_20m_buff = INLET_ERR_TIME;
inlet_2m_buff = INLET_SET_TIME;
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
return;
}
else if ((j > INLET_SET_TIME)&&(softener_flag == 1)) /* 最后一次进水结束处理 */
{
inlet_20m_buff = INLET_ERR_TIME;
inlet_2m_buff = INLET_SET_TIME;
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
return;
}
}
return;
}
else if ((level)&&(!inlet_time)) /* 当传递参数只有水位为真时,运行补水的进水流程 */
{
if (water_full_flag != 1)
{
// Inlet_OPT = 0;
// Inlet_OPT_1 = 0;
output_buff |= INLET;
}
if (inlet_20m_buff > 0)
inlet_20m_buff --;
if (inlet_2m_buff > 0)
{
inlet_2m_buff --;
process_left_time --;
}
if (water_buff == water_level_buff)
{
inlet_20m_buff = INLET_ERR_TIME;
inlet_2m_buff = INLET_SET_TIME;
// Inlet_OPT = 1;
// Inlet_OPT_1 = 1;
output_buff &= (~INLET);
water_full_flag = 1;
return;
}
else if (inlet_20m_buff <= 0)
{
err_buff = INLET_OVTIME_ERR;
inlet_20m_buff = INLET_ERR_TIME;
return;
}
}
else if (cycle) /* 当传递参数只有循环次数为真时,运行补进水流程,本程序未用此流程 */
{
if (cycle_start_flag != 1)
{
cycle_buff = cycle;
cycle_start_flag = 1;
}
i = cycle_buff;
i &= 0x80;
// cycle_buff = cycle_buff << 1;
if (i != 0)
{
// Inlet_OPT = 0;
// Inlet_OPT_1 = 0;
output_buff |= INLET;
if (inlet_2m_buff > 0)
inlet_2m_buff --;
if ((INLET_SET_TIME - inlet_2m_buff) == 35)
{
// Inlet_OPT = 1;
// Inlet_OPT_1 = 1;
output_buff &= (~INLET);
inlet_2m_buff = INLET_SET_TIME;
cycle_buff = cycle_buff << 1;
if (cycle_buff == 0)
{
// if ((program_buff == SPEEDY)||(program_buff == FASTEST))
mot_cycle_buff = MOT_STOP;
output_buff &= (~CW);
output_buff &= (~CCW);
}
// operation_counter ++;
pass_time_counter ++;
}
}
else if (i == 0)
{
if (inlet_2m_buff > 0)
inlet_2m_buff --;
if ((INLET_SET_TIME - inlet_2m_buff) == 30)
{
inlet_2m_buff = INLET_SET_TIME;
cycle_buff = cycle_buff << 1;
// operation_counter ++;
pass_time_counter ++;
if (cycle_buff == 0)
{
/* if (program_buff == SPEEDY)
{
cycle_start_flag = 0;
operation_counter += 9;
pass_time_counter ++;
}
if (program_buff == FASTEST)
{
cycle_start_flag = 0;
operation_counter += 5;
pass_time_counter ++;
}
else if ((program_buff != SPEEDY)&&(program_buff != FASTEST))*/
{
mot_cycle_buff = MOT_STOP;
output_buff &= (~CW);
output_buff &= (~CCW);
process_left_time = 0; // here need check the process left time
cycle_start_flag = 0;
operation_counter += 8;
pass_time_counter ++;
}
}
}
}
}
else
return;
}
/******************************************************************************************
void drain( void ): 排水过程处理程序
******************************************************************************************/
void drain( void )
{
// Drain_OPT = 0;
// Drain_OPT_1 = 0;
output_buff |= DRAIN; /* 排水开始 */
if (drain_8m_buff > 0)
drain_8m_buff --; /* 排水8m变量计时 */
if (process_left_time == 0) /* 重置过程剩余时间 */
process_left_time = drain_2m_buff;
if ((drain_2m_buff > 0)&&(drain_empty_flag == 0))
{
drain_2m_buff --; /* 排水时间变量计时 */
process_left_time --;
}
if (drain_2m_buff == 0)
{
}
if (water_buff == 0) /* 正常排水时,排水结束处理 */
{
if (drain_2m_buff < 119)
{
if (drain_60s_buff > 0)
{
drain_60s_buff --;
process_left_time = drain_60s_buff;
}
if (drain_60s_buff == 0)
{
drain_60s_buff = DRAIN_CONT_TIME;
drain_8m_buff = DRAIN_ERR_TIME;
drain_2m_buff = DRAIN_SET_TIME;
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
save_water_once_flag = 0;
return;
}
}
else if (drain_2m_buff == 119) /* 开始排水时水位即为0的排水过程处理 */
{
drain_empty_flag = 1;
if (drain_10s_buff > 0)
{
drain_10s_buff --;
// process_left_time = drain_10s_buff;
}
if (drain_20s_buff > 0)
{
drain_20s_buff --;
process_left_time = drain_20s_buff;
}
if (drain_20s_buff == 0)
{
drain_10s_buff = DRAIN_CONT_TIME_A;
drain_20s_buff = DRAIN_CONT_TIME_B;
drain_8m_buff = DRAIN_ERR_TIME;
drain_2m_buff = DRAIN_SET_TIME;
drain_empty_flag = 0;
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
save_water_once_flag = 0;
return;
}
else if (drain_10s_buff == 0)
{
if (machine_type == MACHINE_A)
{
drain_10s_buff = DRAIN_CONT_TIME_A;
drain_20s_buff = DRAIN_CONT_TIME_B;
drain_8m_buff = DRAIN_ERR_TIME;
drain_2m_buff = DRAIN_SET_TIME;
drain_empty_flag = 0;
process_left_time = 0;
operation_counter ++;
pass_time_counter ++;
save_water_once_flag = 0;
return;
}
}
}
}
else if (drain_8m_buff == 0) /* 排水超时处理 */
{
drain_8m_buff = DRAIN_ERR_TIME;
drain_2m_buff = DRAIN_SET_TIME;
drain_10s_buff = DRAIN_CONT_TIME_A;
drain_20s_buff = DRAIN_CONT_TIME_B;
drain_60s_buff = DRAIN_CONT_TIME;
process_left_time = drain_2m_buff;
err_buff = DRAIN_ERR;
return;
}
else
return;
}
/******************************************************************************************
void soak(unsigned int soak_time): 浸泡过程处理程序
******************************************************************************************/
void soak(unsigned int soak_time)
{
unsigned char i;
if (water_full_flag == 0)
{
i = water_level_buff - water_buff; /* 判定浸泡运行中水位下降是否超过一档 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -