这段代码是按键部分的处理,其中有3个按键,童锁键,出热水键和出冷水键。出冷水需要短按冷水键,对应的冷水阀和冰胆进水阀打开;出热水需要先短按童锁键解锁,然后短按热水键热水键才被打开 /*按键工作*/ unsigned char statu = 0; static char shot=0;// status hot static char scold= 0;//status cold static char child = 0;//童锁 static unsigned long cold_key_press_tick=0; static unsigned long hot_key_press_tick=0; static unsigned long child_key_press_tick=0; static unsigned long cold_key_delay_tick=0; static unsigned long hot_key_delay_tick=0; static unsigned long child_key_delay_tick=0; static int dchild = 0;//顾名思义,dchild => delay child static int dhot = 0; static int dcold = 0;//delay cold char delay_hot=0; char delay_cold= 0; char delay_child = 0; unsigned long G_Tick = 0;//冷水阀G计时时间 static unsigned long H_Off_Tick = 0;//H阀关闭计时时间 static unsigned long H_On_Tick = 0;//H阀打开计时时间 void Key_Work(void) { // static KEY_TYPE key_type_temp = OFF_KEY; static char hchange = 0,cchange = 0,child_change = 0;//hot change ,cold change 设置翻转 #if 1 if (READ_CHILD_KEY_VALUE)//读取童锁键值,但是有问题的是,if里面应该是一个表达式,表达式为真时,才会执行if里面的内容,so,READ_CHILD_KEY_VALUE == 1 { if (gTick - child_key_press_tick >= 3*1000)//按键按下时间超过9*1000ms { child = 1; } } else { child = 0; child_key_press_tick = gTick; } if(child == 1)//长按童锁键 { child = 0;//按下后清空原状态 if(key_type == CHILD_KEY) { child_change = !child_change; key_type = OFF_KEY; Trans_dat_append(STATE_23);//整机自清洗指令 if(child_change)//排水状态 { System_Sta.s.clean_self_cmd = FLAG_ON;//自排水命令标志关闭 System_Sta.s.drain_close_flag = 1;//清除标志位 /*加蜂鸣器时间判断是否进入此循环,进入排水状态,蜂鸣器响2声*/ System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200);//阻塞时间200ms System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; System_Data.flash_water_flag[0]='0'; System_Data.flash_water_flag[1]='1';//开始排水 Trans_dat_append(STATE_23); /*在排水状态让按键短按"失效",一直没成功???,放在这里,似乎成功了*/ if((dchild == 1) || (dhot == 1) || (dcold == 1))//短按 { dchild = dhot = dcold = 0; delay_cold = delay_child = delay_hot = 1; hot_key_delay_tick = cold_key_delay_tick = child_key_delay_tick = 0;//短按 hot_key_press_tick = cold_key_press_tick = child_key_press_tick = 0;//长按 Set_HotWaterValve_F(Bit_RESET); Set_ColdWaterValve_G(Bit_RESET); Set_NormalWaterValve_H(Bit_RESET); } /**************/ } #if 0 else//不进入自排水状态,蜂鸣器响3声 { System_Sta.s.clean_self_cmd = FLAG_OFF;//未收到自排水命令 System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200);//阻塞时间200ms System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200);//阻塞时间200ms System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; System_Data.flash_water_flag[0]='0'; System_Data.flash_water_flag[0]='2';//停止排水 Trans_dat_append(STATE_23); System_Sta.s.drain_close_flag = 1; child_change = 0; } #endif } } #endif #if 1 if(READ_HOT_KEY_VALUE) { if(gTick-hot_key_press_tick>=3*1000)//“热键”按下时间超过9*1000ms { shot = 1; } } else { shot = 0; hot_key_press_tick = gTick; } if(READ_COLD_KEY_VALUE) { if(gTick - cold_key_press_tick >= 3*1000)//“冷键”按下时间超过9*1000ms { scold = 1; } } else { scold = 0; cold_key_press_tick = gTick; } if(scold==1 && shot==1)//同时按下冷水键和热水键,长按 { Save_Data.s.self_clean_flag = 0;//保存掉电前自排水完成状态,自排水是"童锁"+"冷水" i2cWriteBuffer1(AT24C02_ADDR,AT24C02_REG,sizeof(SAVE_DATA_UNION),(u8*)&Save_Data);/*写入数据*/ /*初始化整个联合体数组*/ for (int i = 0; i < sizeof(STA_UNION); i++) { System_Sta.sta = 0; } memset((void *)(&System_Data),0,sizeof(DATA_STRUCT)); //开启蜂鸣器 if(TIMER_RESET==System_Sta.s.beep_timer_flag) { System_Sta.s.beep_timer_flag = TIMER_RUN; } System_Data.flash_water_flag[0]='0'; System_Data.flash_water_flag[1]='2';/*停止清洗*/ Trans_dat_append(STATE_23);//整机自清洗指令 while(1); } if(scold==1 && child==1) //按下冷水键和童锁键10s处于排气过程 (问题点???) { System_Sta.s.clean_self_cmd = FLAG_OFF;//自排水标志位turn off Save_Data.s.self_clean_flag = 0;//保存掉电前自排水完成状态 System_Sta.s.Vent_Flag = FLAG_ON;//自排气标志位打开 //System_Sta.s.Vent_Flag = FLAG_ON; //System_Data.Cold_Water_G_Tick = 0;// //System_Sta.s.Cold_Water_G_Flag = FLAG_OFF; //System_Data.Normal_Water_H_Tick = 0; //System_Sta.s.Normal_Water_H_Flag = FLAG_OFF; i2cWriteBuffer1(AT24C02_ADDR,AT24C02_REG,sizeof(SAVE_DATA_UNION),(u8*)&Save_Data);/*写入数据*/ // for (int i = 0; i < sizeof(STA_UNION); i++) // { // System_Sta.sta = 0; // } // // memset((void *)(&System_Data),0,sizeof(DATA_STRUCT)); System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200);//阻塞时间200ms System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200);//阻塞时间200ms System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; System_Data.flash_water_flag[0]='0'; System_Data.flash_water_flag[1]='2';/*停止清洗*/ Trans_dat_append(STATE_23);//整机自清洗指令 while(1);//如果次处加上while(1)则无法打开冷水和热水阀 } if(shot == 1 && READ_COLD_KEY_VALUE == 0)//只按下热水键长按 { if(key_type == HOT_KEY) { hchange = !hchange;//hot change key_type = OFF_KEY; if(System_Sta.s.hot_close_flag == 1) { if(Bit_RESET==Read_WaterShortagDetection()) { System_Data.fixed_state[1] = '1'; System_Sta.s.hot_close_flag = 0; if (Save_Data.s.machine_type != DY_100B) { System_Data.ntc2_setting_temperature = 0; } // u8 tem[2] = {0}; // tem[0] = System_Data.ntc1_setting_temperature; // tem[1] = System_Data.ntc2_setting_temperature; // i2cWriteBuffer1(AT24C02_ADDR, AT24C02_REG_TEM, sizeof(tem), (u8*)&tem);/*写入数据*/ Trans_dat_append(STATE_12); System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200);//阻塞时间200ms System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50);//阻塞时间50ms System_Sta.s.beep_timer_flag = TIMER_RESET; // GPIO_WriteBit(GPIOC, GPIO_Pin_12, 1); // GPIO_WriteBit(GPIOA, GPIO_Pin_13, 1); System_Sta.s.to_heat1_cmd_flag = FLAG_ON; System_Sta.s.to_heat2_cmd_flag = FLAG_ON; Trans_dat_append(STATE_03); } else { System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50); System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200); System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50); System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200); System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50); System_Sta.s.beep_timer_flag = TIMER_RESET; hchange = 0;//hot_key change } } else { // GPIO_WriteBit(GPIOC, GPIO_Pin_12, 0); // GPIO_WriteBit(GPIOA, GPIO_Pin_13, 0); // System_Data.ntc1_setting_temperature = 0; // if (Save_Data.s.machine_type == DY_100B) // { // System_Data.ntc2_setting_temperature = 0; // } // else // { // System_Data.ntc2_setting_temperature = 0; // } // u8 tem[2] = {0}; // tem[0] = System_Data.ntc1_setting_temperature; // tem[1] = System_Data.ntc2_setting_temperature; // i2cWriteBuffer1(AT24C02_ADDR, AT24C02_REG_TEM, sizeof(tem), (u8*)&tem);/*写入数据*/ Trans_dat_append(STATE_12); System_Data.fixed_state[1] = '0'; System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50); System_Sta.s.beep_timer_flag = TIMER_RESET; Set_HotTube_1(Bit_RESET); Set_HotTube_2(Bit_RESET); System_Sta.s.hot_close_flag = 1; Trans_dat_append(STATE_03); } } } if(scold == 1 && READ_HOT_KEY_VALUE == 0)//只按下冷水键 { if(key_type == COLD_KEY) { cchange = !cchange;//冷键翻转 //GPIO_WriteBit(GPIOA, GPIO_Pin_14, cchange); key_type = OFF_KEY; Trans_dat_append(STATE_02); if(cchange) { System_Data.fixed_state[2] = '1'; Set_IceTube(Bit_SET); System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50); System_Sta.s.beep_timer_flag = TIMER_RESET; Block_Timer(200); System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50); System_Sta.s.beep_timer_flag = TIMER_RESET; } else { System_Data.fixed_state[2] = '0'; Set_IceTube(Bit_RESET); System_Sta.s.beep_timer_flag = TIMER_RUN; Block_Timer(50); System_Sta.s.beep_timer_flag = TIMER_RESET; } Trans_dat_append(STATE_02); } } if(Bit_SET==Read_WaterShortagDetection()||System_Data.ntc1_temperature>=95||System_Data.ntc2_temperature>=95) { GPIO_WriteBit(GPIOC, GPIO_Pin_12, 0);//hot tube 1 GPIO_WriteBit(GPIOA, GPIO_Pin_13, 0);//hot tube 2 hchange = 0; } #endif #ifdef KEY_DELAY_S // 加入按键持续时间判断 // static unsigned long cold_key_delay_tick=0; // static unsigned long hot_key_delay_tick=0; // static unsigned long child_key_delay_tick=0; #if 0 char delay_hot=0; char delay_cold= 0; char delay_child = 0; #endif // child if (READ_CHILD_KEY_VALUE) { if (gTick - child_key_delay_tick >= KEY_DELAY_S_LOW * 1000 //KEY_DELAY_S_LOW单位为second,*1000为ms && gTick - child_key_delay_tick <= KEY_DELAY_S_HIGH * 1000) { dchild = 1; } else if (gTick - child_key_delay_tick > KEY_DELAY_S_HIGH * 1000) { dchild = 0; } } else { // 捕捉到 KEY_DELAY_S_LOW 到 KEY_DELAY_S_HIGH 区间内的有效按键 if (dchild == 1) { dchild = 0; delay_child = 1; } child_key_delay_tick = gTick; } // hot if (READ_HOT_KEY_VALUE) { if (gTick - hot_key_delay_tick >= KEY_DELAY_S_LOW * 1000 && gTick - hot_key_delay_tick <= KEY_DELAY_S_HIGH * 1000) { dhot = 1;// } else if (gTick - hot_key_delay_tick > KEY_DELAY_S_HIGH * 1000) { dhot = 0; } } else { // 捕捉到 KEY_DELAY_S_LOW 到 KEY_DELAY_S_HIGH 区间内的有效按键 if (dhot == 1) { dhot = 0; delay_hot = 1; } hot_key_delay_tick = gTick; } // cold if (READ_COLD_KEY_VALUE) { if (gTick - cold_key_delay_tick >= KEY_DELAY_S_LOW * 1000 && gTick - cold_key_delay_tick <= KEY_DELAY_S_HIGH * 1000) { dcold = 1; } else if (gTick - cold_key_delay_tick > KEY_DELAY_S_HIGH * 1000) { dcold = 0; } } else { // 捕捉到 KEY_DELAY_S_LOW 到 KEY_DELAY_S_HIGH 区间内的有效按键 if (dcold == 1) { dcold = 0; delay_cold = 1; } cold_key_delay_tick = gTick; } // 如果有超过1个按键在动作,则复位全部按键标志位 int delay_key = delay_cold + delay_hot + delay_child; if (delay_key > 1) { delay_cold = delay_hot = delay_child = 0; delay_key = 0; } #if 0 //如果冷水键和热水键同时按下,则复位全部 int delay_key1 = delay_cold + delay_hot;//delay_key1 表示同时按下冷水键和热水键的延时 if(delay_key1 > 1) { delay_cold = delay_hot = 0; delay_key1 = 0; } //如果冷水键和童锁键同时按下,则进入排气过程 int delay_key2 = delay_child + delay_cold;//delay_key2表示长按冷水键和童锁键 if(delay_key2 > 1) { System_Sta.s.Vent_Cmd = FLAG_ON; } #endif #endif // KEY_DELAY_S if(Save_Data.s.machine_type==DY_75)/*按键失效*/ { System_Sta.s.key_timer_flag = TIMER_RESET; } else if(Save_Data.s.machine_type==DY_400)/*童锁键改为温水键*/ { Child_Key_On_Flag = 1; } //等待捕捉到稳定按键值 if((TIMER_RUN==System_Sta.s.key_timer_flag)&& (System_Data.key_tick >= KEY_DELAY_MS) #ifdef KEY_DELAY_S && (delay_key == 1) #endif // KEY_DELAY_S ) { //复位按键去抖定时器 System_Data.key_tick = 0; System_Sta.s.key_timer_flag = TIMER_RESET; //更新按键值 key_type_temp = key_type; #ifdef KEY_DELAY_S if (delay_child == 1) { key_type_temp = CHILD_KEY; } else if (delay_cold == 1) { key_type_temp = COLD_KEY; } else if (delay_hot == 1) { key_type_temp = HOT_KEY; } else { key_type_temp = OFF_KEY; } #endif // KEY_DELAY_S //开启蜂鸣器 if(TIMER_RESET==System_Sta.s.beep_timer_flag) { System_Sta.s.beep_timer_flag = TIMER_RUN; } } if (System_Data.fill_water_number[sizeof(System_Data.fill_water_number)-3] == '0' &&\ System_Data.fill_water_number[sizeof(System_Data.fill_water_number)-2] == '1' &&\ System_Data.fill_water_number[sizeof(System_Data.fill_water_number)-1] == '2' ) { // if (key_type_temp != System_Data.last_key_type) // { // key_type_temp = OFF_KEY; // // return; // } } //处理按键值 switch(key_type_temp) { case CHILD_KEY://此case为选择童锁按键 //System_Data.child_flag_tick = 0; if(Save_Data.s.machine_type==DY_400)//DY_400为一个热水泵+一个冷水泵 { if((CHILD_KEY==System_Data.last_key_type&&FLAG_ON==System_Sta.s.water_on_flag)||\ (System_Sta.s.Liquid_shortage_flag == FLAG_ON)) { Set_NormalWaterValve_H(Bit_RESET);//温水键复位 //System_Data.cold_water_time += System_Data.cold_water_flag_tick/1000; System_Sta.s.child_timer_flag = TIMER_RESET; System_Data.child_flag_tick = 0; System_Sta.s.normal_water_on_flag = FLAG_OFF; System_Sta.s.pre_out_normal_water_flag = 0; } else /*准备打开温水开关*/ { System_Sta.s.pre_out_normal_water_flag = 1; if(TIMER_RESET!=System_Sta.s.nfc_tick_flag) { Trans_dat_append(REQUEST_RFID_CHANGE_06);/*上报数据*/ System_Data.rfid_number_ascill[24]='0'; System_Data.rfid_number_ascill[25]='0'; } Trans_dat_append(STATE_22);/*上报数据 请求出水*/ } } else { System_Sta.s.child_timer_flag = TIMER_RUN; Child_Key_On_Flag = 1;/*解锁*/ } break; case HOT_KEY://此case为热键 if((FLAG_OFF==Child_Key_On_Flag) || \ (HOT_KEY==System_Data.last_key_type&&FLAG_ON==System_Sta.s.water_on_flag)|| \ (System_Sta.s.Liquid_shortage_flag == FLAG_ON)) { Set_HotWaterValve_F(Bit_RESET);//复位热水键 System_Data.hot_water_time += System_Data.hot_water_flag_tick/1000; System_Sta.s.hot_water_timer_flag = TIMER_RESET;//定时器复位 System_Data.hot_water_flag_tick = 0;//计时器清0 System_Sta.s.hot_water_on_flag = FLAG_OFF; System_Sta.s.pre_out_hot_water_flag = 0; if(FLAG_OFF==Child_Key_On_Flag) { System_Data.water_out_flag[0] = '0'; System_Data.water_out_flag[1] = '4';/*童锁未解锁拒绝出水*/ Trans_dat_append(WATER_OUT_REPORT_21);/*上报数据*/ if(System_Sta.s.nfc_tick_flag == TIMER_RUN)/*nfc出水中*/ { System_Data.rfid_number_ascill[24] = '0'; System_Data.rfid_number_ascill[25] = '4'; Trans_dat_append(REQUEST_RFID_CHANGE_06);/*上报数据*/ } if(FLAG_OFF==System_Sta.s.scaven_end_flag) { System_Sta.s.scaven_hot_flag = FLAG_ON; Trans_dat_append(ORDER_REPORT_04);/*上报数据*/ } } } else /*准备打开热水开关*/ { System_Sta.s.pre_out_hot_water_flag = 1; Trans_dat_append(STATE_22);/*上报数据 请求出水*/ if(TIMER_RESET!=System_Sta.s.nfc_tick_flag) { Trans_dat_append(REQUEST_RFID_CHANGE_06);/*上报数据*/ System_Data.rfid_number_ascill[24]='0'; System_Data.rfid_number_ascill[25]='0'; } if(Save_Data.s.machine_type!=DY_400) { System_Data.child_flag_tick = 0;/*清0童锁计数器*/ } } break; case COLD_KEY: if((COLD_KEY==System_Data.last_key_type&&FLAG_ON==System_Sta.s.water_on_flag)|| \ (System_Sta.s.Liquid_shortage_flag == FLAG_ON && FLAG_ON == System_Sta.s.Normal_Water_H_Flag )) { System_Data.cold_water_time += System_Data.cold_water_flag_tick/1000; System_Sta.s.cold_water_timer_flag = TIMER_RESET; System_Data.cold_water_flag_tick = 0; System_Sta.s.cold_water_on_flag = FLAG_OFF; System_Sta.s.pre_out_cold_water_flag = 0; System_Data.Normal_Water_H_Off_Time += System_Data.Normal_Water_H_Tick/1000; System_Sta.s.Normal_Water_Timer_Flag = TIMER_RESET; System_Data.Normal_Water_H_Tick = 0; System_Sta.s.Normal_Water_H_Flag = FLAG_OFF; if(System_Sta.s.Normal_Water_H_Flag) { System_Sta.s.Normal_Water_H_Flag = FLAG_ON; } if(System_Sta.s.Normal_Water_Timer_Flag == TIMER_RESET) { System_Sta.s.Normal_Water_Timer_Flag = TIMER_RUN; } Set_NormalWaterValve_H(Bit_RESET);//此处H阀表示的是冰胆的进水阀,turn off it!!!,增加了H阀控制冰胆 if(gTick - H_Off_Tick > 200 && statu == 1)//关闭状态时statu应该从1到0,打开状态为从0到1 { H_Off_Tick = gTick; statu = 0; Set_ColdWaterValve_G(Bit_RESET); } /* if(TIMER_RUN == System_Sta.s.Normal_Water_Timer_Flag && System_Data.Normal_Water_H_Tick > 200) { Set_ColdWaterValve_G(Bit_RESET); } */ } else /*准备打开冷水开关*/ { System_Sta.s.pre_out_cold_water_flag = 1; Trans_dat_append(STATE_22);/*上报数据 请求出水*/ if(TIMER_RESET!=System_Sta.s.nfc_tick_flag) { Trans_dat_append(REQUEST_RFID_CHANGE_06);/*上报数据*/ System_Data.rfid_number_ascill[24]='0'; System_Data.rfid_number_ascill[25]='0'; } } break; case OFF_KEY: break; default : break; } //更新上次的有效按键 if(OFF_KEY!=key_type_temp && CHILD_KEY!=key_type_temp) { System_Data.last_key_type = key_type_temp; } if(Save_Data.s.machine_type==DY_400) { if(CHILD_KEY == key_type_temp) { System_Data.last_key_type = key_type_temp; } } key_type_temp = OFF_KEY; if(System_Sta.s.pre_out_cold_water_flag==1||\ System_Sta.s.pre_out_normal_water_flag ==1||\ System_Sta.s.pre_out_hot_water_flag ==1) { if(TIMER_RESET==System_Sta.s.wait_water_tick_flag) { System_Sta.s.wait_water_tick_flag = TIMER_RUN; } } else { System_Sta.s.wait_water_tick_flag = TIMER_RESET; System_Data.wait_water_tick = 0; } if(System_Data.wait_water_tick>5000) { System_Sta.s.pre_out_cold_water_flag=0; System_Sta.s.pre_out_normal_water_flag =0; System_Sta.s.pre_out_hot_water_flag =0; System_Sta.s.wait_water_tick_flag = TIMER_RESET; System_Data.wait_water_tick = 0; } //允许热水出水 if(System_Sta.s.pre_out_hot_water_flag == 2) { Set_HotWaterValve_F(Bit_SET);//热水阀置位 Set_NormalWaterValve_H(Bit_RESET);//温水阀复位 if(gTick - H_Off_Tick > 200 && statu == 1)//关闭状态时statu应该从1到0,打开状态为从0到1 { H_Off_Tick = gTick; statu = 0; Set_ColdWaterValve_G(Bit_RESET);//在温水阀复位后的200ms冷水阀复位 } //Set_ColdWaterValve_G(Bit_RESET);//在温水阀复位后的200ms冷水阀复位 if(TIMER_RESET==System_Sta.s.hot_water_timer_flag) { System_Sta.s.hot_water_timer_flag = TIMER_RUN; } System_Sta.s.hot_water_on_flag = FLAG_ON; System_Sta.s.pre_out_hot_water_flag = 0; System_Sta.s.pre_out_cold_water_flag = 0; if(System_Sta.s.cold_water_on_flag)/*更新 切换出水相关标志位*/ { System_Sta.s.Update_Out_Water_Time_flag = FLAG_ON; } if(Save_Data.s.machine_type==DY_400&&System_Sta.s.child_timer_flag==1)/*更新 切换出水相关标志位*/ { System_Sta.s.Update_Out_Water_Time_flag = FLAG_ON; } if(Save_Data.s.machine_type==DY_400) { /*停止温水*/ System_Data.child_flag_tick = 0; System_Sta.s.child_timer_flag = TIMER_RESET; System_Sta.s.normal_water_on_flag = FLAG_OFF; Set_NormalWaterValve_H(Bit_RESET); } /*停止冷水*/ System_Data.cold_water_time += System_Data.cold_water_flag_tick/1000; System_Data.cold_water_flag_tick = 0; System_Sta.s.cold_water_timer_flag = TIMER_RESET; System_Sta.s.cold_water_on_flag = FLAG_OFF; System_Data.Normal_Water_H_Off_Time += System_Data.Normal_Water_H_Tick/1000; System_Sta.s.Normal_Water_H_Flag = FLAG_OFF; System_Data.Normal_Water_H_Tick = 0; System_Sta.s.Normal_Water_Timer_Flag = TIMER_RESET; /*取水容量定时器和标志位*/ System_Data.Capacity_Control_Time += System_Data.Capacity_Control_Tick/1000; System_Sta.s.Capacity_Control_Timer_Flag = FLAG_OFF; System_Data.Capacity_Control_Tick = 0; System_Sta.s.Capacity_Control_Timer_Flag = TIMER_RESET; if(System_Sta.s.Normal_Water_H_Flag) { System_Sta.s.Normal_Water_H_Flag = FLAG_ON; } if(System_Sta.s.Normal_Water_Timer_Flag == TIMER_RESET) { System_Sta.s.Normal_Water_Timer_Flag = TIMER_RUN; } if(System_Sta.s.Capacity_Control_Flag) { System_Sta.s.Capacity_Control_Flag = FLAG_ON; } if(System_Sta.s.Capacity_Control_Timer_Flag == TIMER_RESET) { System_Sta.s.Capacity_Control_Timer_Flag = TIMER_RUN; } /*在冷水出水过程中增加阀H动作??? Add by HeJun */ if(System_Data.Capacity_Control_Tick > 45000 && TIMER_RUN == System_Sta.s.Capacity_Control_Timer_Flag)//当阀H的水量时间到了45s,则关闭H阀 { //H_On_Tick = gTick; //statu = 1; Set_NormalWaterValve_H(Bit_RESET);//此处H阀表示的是冰胆的进水阀,turn off it!!!,增加了H阀控制冰胆 if(TIMER_RUN == System_Sta.s.Normal_Water_Timer_Flag && System_Data.Normal_Water_H_Tick > 200) { Set_ColdWaterValve_G(Bit_RESET); } } /* if(gTick - H_On_Tick > 45000 && statu == 0) { H_On_Tick = gTick; statu = 1; Set_NormalWaterValve_H(Bit_RESET);//此处H阀表示的是冰胆的进水阀,turn off it!!!,增加了H阀控制冰胆 if(gTick - H_Off_Tick > 200 && statu == 1) { H_Off_Tick = gTick; statu = 0; Set_ColdWaterValve_G(Bit_RESET); } } */ } //允许冷水出水 else if(System_Sta.s.pre_out_cold_water_flag == 2) { Set_ColdWaterValve_G(Bit_SET); Set_NormalWaterValve_H(Bit_RESET); Set_HotWaterValve_F(Bit_RESET); Set_InletValve_I(Bit_RESET);//此处阀I为热罐进水阀,turn off it!!! if(TIMER_RESET==System_Sta.s.cold_water_timer_flag) { System_Sta.s.cold_water_timer_flag = TIMER_RUN; } if(System_Sta.s.cold_water_on_flag) { System_Sta.s.cold_water_on_flag = FLAG_ON; } if(TIMER_RESET == System_Sta.s.Normal_Water_Timer_Flag) { System_Sta.s.Normal_Water_Timer_Flag = TIMER_RUN; } if(System_Sta.s.Normal_Water_H_Flag) { System_Sta.s.Normal_Water_H_Flag = FLAG_ON; } System_Sta.s.cold_water_on_flag = FLAG_ON; System_Sta.s.pre_out_cold_water_flag = 0; System_Sta.s.pre_out_hot_water_flag = 0; System_Sta.s.Normal_Water_H_Flag = FLAG_ON; //System_Data.Capacity_Control_Tick = 0; if(System_Sta.s.hot_water_on_flag)/*更新 切换出水相关标志位*/ { System_Sta.s.Update_Out_Water_Time_flag = FLAG_ON; } if(Save_Data.s.machine_type==DY_400&&System_Sta.s.child_timer_flag==1)/*更新 切换出水相关标志位*/ { System_Sta.s.Update_Out_Water_Time_flag = FLAG_ON; } if(gTick - G_Tick > 200 && statu == 0)//此段代码加载试验仅第一次有效 { statu = 1; G_Tick = gTick; Set_NormalWaterValve_H(Bit_SET); } /* if(TIMER_RUN == System_Sta.s.cold_water_timer_flag && System_Data.cold_water_flag_tick > 200) { Set_NormalWaterValve_H(Bit_SET); } */ /*停止热水*/ System_Data.hot_water_time += System_Data.hot_water_flag_tick/1000; System_Data.hot_water_flag_tick = 0; System_Sta.s.hot_water_timer_flag = TIMER_RESET; System_Sta.s.hot_water_on_flag = FLAG_OFF; Set_HotWaterValve_F(Bit_RESET); if(Save_Data.s.machine_type==DY_400) { /*停止温水*/ System_Data.child_flag_tick = 0; System_Sta.s.child_timer_flag = TIMER_RESET; System_Sta.s.normal_water_on_flag = FLAG_OFF; Set_NormalWaterValve_H(Bit_RESET); } } if(Save_Data.s.machine_type==DY_400) { //允许温水出水 if(System_Sta.s.pre_out_normal_water_flag == 2) { Set_HotWaterValve_F(Bit_RESET); Set_ColdWaterValve_G(Bit_RESET); Set_NormalWaterValve_H(Bit_SET); if(TIMER_RESET==System_Sta.s.child_timer_flag) { System_Sta.s.child_timer_flag = TIMER_RUN; } System_Sta.s.normal_water_on_flag = FLAG_ON; System_Sta.s.pre_out_hot_water_flag = 0; System_Sta.s.pre_out_cold_water_flag = 0; System_Sta.s.pre_out_normal_water_flag = 0; if(System_Sta.s.cold_water_on_flag)/*更新 切换出水相关标志位*/ { System_Sta.s.Update_Out_Water_Time_flag = FLAG_ON; } if(System_Sta.s.hot_water_on_flag)/*更新 切换出水相关标志位*/ { System_Sta.s.Update_Out_Water_Time_flag = FLAG_ON; } /*停止热水*/ System_Data.hot_water_time += System_Data.hot_water_flag_tick/1000; System_Data.hot_water_flag_tick = 0; System_Sta.s.hot_water_timer_flag = TIMER_RESET; System_Sta.s.hot_water_on_flag = FLAG_OFF; Set_HotWaterValve_F(Bit_RESET); /*出水容量未满*/ System_Data.Capacity_Control_Time += System_Data.Capacity_Control_Tick/1000; System_Sta.s.Capacity_Control_Timer_Flag = TIMER_RESET; System_Data.Capacity_Control_Tick = 0; System_Sta.s.Capacity_Control_Flag = FLAG_OFF; /*冰胆进水阀关闭*/ System_Data.Normal_Water_H_Off_Time += System_Data.Normal_Water_H_Tick/1000; System_Sta.s.Normal_Water_H_Flag = FLAG_OFF; System_Data.Normal_Water_H_Tick = 0; System_Sta.s.Normal_Water_Timer_Flag = TIMER_RESET; /*取水容量标志位*/ if(System_Sta.s.Capacity_Control_Flag) { System_Sta.s.Capacity_Control_Flag = FLAG_ON; } if(System_Sta.s.Capacity_Control_Timer_Flag == TIMER_RESET) { System_Sta.s.Capacity_Control_Timer_Flag = TIMER_RUN; } if(System_Sta.s.Normal_Water_H_Flag) { System_Sta.s.Normal_Water_Timer_Flag = FLAG_ON; } if(System_Sta.s.Normal_Water_Timer_Flag == TIMER_RESET) { System_Sta.s.Normal_Water_Timer_Flag = TIMER_RUN; } /*停止冷水*/ System_Data.cold_water_time += System_Data.cold_water_flag_tick/1000; System_Data.cold_water_flag_tick = 0; System_Sta.s.cold_water_timer_flag = TIMER_RESET; System_Sta.s.cold_water_on_flag = FLAG_OFF; /*在冷水出水过程中增加阀H动作??? Add by HeJun */ if(System_Data.Capacity_Control_Tick > 45000 && TIMER_RUN == System_Sta.s.Capacity_Control_Timer_Flag)//当阀H的水量时间到了45s,则关闭H阀 { //H_On_Tick = gTick; //statu = 1; Set_NormalWaterValve_H(Bit_RESET);//此处H阀表示的是冰胆的进水阀,turn off it!!!,增加了H阀控制冰胆 if(TIMER_RUN == System_Sta.s.Normal_Water_Timer_Flag && System_Data.Normal_Water_H_Tick > 200) { Set_ColdWaterValve_G(Bit_RESET); } } /* if(gTick - H_On_Tick > 45000 && statu == 0) { H_On_Tick = gTick; statu = 1; Set_NormalWaterValve_H(Bit_RESET);//此处H阀表示的是冰胆的进水阀,turn off it!!!,增加了H阀控制冰胆 if(gTick - H_Off_Tick > 200 && statu == 1) { H_Off_Tick = gTick; statu = 0; Set_ColdWaterValve_G(Bit_RESET); } } */ } /*温水键工作*/ if((TIMER_RUN==System_Sta.s.child_timer_flag) && (System_Data.child_flag_tick>HOT_DELAY_MS)) { //System_Data.cold_water_time += System_Data.cold_water_flag_tick/1000; System_Data.child_flag_tick = 0; System_Sta.s.child_timer_flag = TIMER_RESET; System_Sta.s.normal_water_on_flag = FLAG_OFF; Set_NormalWaterValve_H(Bit_RESET); } } else { /*童锁键工作*/ if((FLAG_ON==Child_Key_On_Flag) && \ (CHILD_DELAY_MS>System_Data.child_flag_tick) && \ (FLAG_ON==System_Sta.s.hot_water_on_flag)) { System_Data.child_flag_tick = 0; } else if(CHILD_DELAY_MS<=System_Data.child_flag_tick) { System_Data.child_flag_tick = 0; System_Sta.s.child_timer_flag = TIMER_RESET; Child_Key_On_Flag = 0; } } /*热水键工作*/ if((TIMER_RUN==System_Sta.s.hot_water_timer_flag) && (System_Data.hot_water_flag_tick>HOT_DELAY_MS)) { System_Data.hot_water_time += System_Data.hot_water_flag_tick/1000; System_Data.hot_water_flag_tick = 0; System_Sta.s.hot_water_timer_flag = TIMER_RESET; System_Sta.s.hot_water_on_flag = FLAG_OFF; Set_HotWaterValve_F(Bit_RESET); } // if( (TIMER_RUN==System_Sta.s.hot_water_timer_flag) &&\ // (0<System_Data.hot_water_flag_tick) &&\ // (HOT_DELAY_MS>System_Data.hot_water_flag_tick) &&\ // (TIMER_RUN==System_Sta.s.hot_water_timer_flag) ) // { // // } /*冷水键工作*/ if((TIMER_RUN==System_Sta.s.cold_water_timer_flag) && (System_Data.cold_water_flag_tick > COLD_DELAY_MS) \ && (TIMER_RUN == System_Sta.s.Normal_Water_Timer_Flag)) { System_Data.cold_water_time += System_Data.cold_water_flag_tick/1000; System_Data.cold_water_flag_tick = 0; System_Sta.s.cold_water_timer_flag = TIMER_RESET; System_Sta.s.cold_water_on_flag = FLAG_OFF; System_Data.Normal_Water_H_Off_Time += System_Data.Normal_Water_H_Tick/1000; System_Sta.s.Normal_Water_H_Flag = FLAG_OFF; System_Data.Normal_Water_H_Tick = 0; System_Sta.s.Normal_Water_Timer_Flag = TIMER_RESET; if(System_Sta.s.Normal_Water_H_Flag) { System_Sta.s.Normal_Water_H_Flag = FLAG_ON; } if(System_Sta.s.Normal_Water_Timer_Flag == TIMER_RESET) { System_Sta.s.Normal_Water_Timer_Flag = TIMER_RUN; } /*在冷水出水过程中增加阀H动作,直接关闭H阀 Add by */ /* if(TIMER_RUN == System_Sta.s.Normal_Water_Timer_Flag && System_Data.Normal_Water_H_Tick > 200) { Set_ColdWaterValve_G(Bit_RESET); } */ Set_NormalWaterValve_H(Bit_RESET);//此处H阀表示的是冰胆的进水阀,turn off it!!!,增加了H阀控制冰胆 if(gTick - H_Off_Tick > 200 && statu == 1) { H_Off_Tick = gTick; statu = 0; Set_ColdWaterValve_G(Bit_RESET); } } } 此段代码中dchild,dhot和dcold都是短按的延时变量,那么当我短按按下任何一个按键,该按键本该有的状态不被触发该用什么方法做?比方说短按冷水键冷水阀和冰胆进水阀不打开,短按童锁键再按热水键,热水阀不打开。 if((dchild == 1) || (dhot == 1) || (dcold == 1))//短按 { dchild = dhot = dcold = 0; delay_cold = delay_child = delay_hot = 1; hot_key_delay_tick = cold_key_delay_tick = child_key_delay_tick = 0;//短按 hot_key_press_tick = cold_key_press_tick = child_key_press_tick = 0;//长按 Set_HotWaterValve_F(Bit_RESET);//热水出水阀复位 Set_ColdWaterValve_G(Bit_RESET);//冷水出水阀复位 Set_NormalWaterValve_H(Bit_RESET);//冰胆进水阀复位 } 这段代码是我尝试的做法,也就是把短按的按键延时变量清0,但是各按键按下后依然有效,现在卡在这里了??? |
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
如果童锁键被置位了,那么热水键就算是按下也不会触发热水阀打开了
假设标志位为1时允许出热水,执行出热水后清除标志位。本次出热水有效。出完热水后禁止,本次操作结束。
建议写成状态机的方式,把事件分成几个状态,各状态间跳转清晰明了。
业务逻辑很简单,
建议重构状态机或者使用RTOS。
代码架构乱,是导致程序猿写&改BUG的主要原因之一
key=Key_scan();
//状态位更改
/*根据最新键值,结合之前的状态,更新状态标志*/
//动作执行
/*根据标志控制输出*/