你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM8S控制的水龙头业务代码问题中的互斥标志位执行同一功能

[复制链接]
hejun96 提问时间:2019-11-30 20:47 /
悬赏1ST金币未解决
     首先这是一段由水龙头控制的程序,主控板通过串口上报数据给ht1621b驱动的显示屏,显示屏只有收到串口的数据后会根据串口显示不同的图标,有问题的程序附在下面,首先在开机后,显示屏上面附带有一个触摸IC按键,显示屏上面的图标轮流闪烁(此过程是水龙头排气过程),直到按键长按10s退出排气,退出排气后可以一档二档出水由STM8S控制增压泵IO口输出(一档为PWM控制的半压输出,二档为全压输出)。在增压泵xmin 后无工作(x表示分钟数)进入自动冲洗状态,这个状态是增压泵可以为一档出水的方式工作清洗水箱中的水,退出的条件有两个:一个是缺水,一个是水泵空转5s,现在缺水时时可以退出的,但是水泵空转5s是通过AD电流采集数据,但是水泵空转5s和缺水退出的条件不一样,而且SystemStatus.work_mode (工作模式:一档和二档出水)和SystemStatus.auto_clean(自清洗模式标志位)是互斥的关系,SystemStatus.zyb_mode(增压泵是PWM半压输出还是全压输出)属于SystemStatus.work_mode的一个子集,要让这两个条件都执行不知道怎么做,但是执行的功能是类似的,有问题的代码都写在下面了,就是不知道该怎么解?


  1. /* 主控板状态信息 */
  2. typedef struct waterbox_info
  3. {
  4.   uint8_t tds;
  5.   uint16_t temperature;
  6.   uint8_t out;//出水  
  7.   uint8_t fullwater;
  8.   uint8_t makewater;
  9.   uint8_t uv;
  10.   uint8_t work_mode;
  11.   uint8_t auto_clean;
  12.   uint8_t err_code;     /*错误码:漏水*/
  13.   uint8_t crc_code;
  14.   uint8_t outair;//自排气
  15.   uint8_t isEmpty;      //水箱无水
  16.   uint8_t zyb;
  17.   uint8_t liquid_level; //liquid level protect
  18.   uint8_t leakwater;  /*漏水*/
  19.   uint8_t jump_outair;//跳过排气
  20.   uint8_t zyb_mode;
  21. }System_t;

  22. /* 结构体 */
  23. System_t SystemStatus = {0};

  24. uint16_t Current_Aver_Buf[ZYB_BUF_LEN]={0};//增压泵平均值缓存区长度
  25. uint16_t temp = 0;
  26. uint16_t temp1 = 0;

  27. #define ZYB_BUF_LEN    20
  28. uint16_t get_current_average_value(uint16_t *buf,uint16_t val)
  29. {
  30.     volatile uint16_t sum = 0,temp = 0;
  31.     volatile uint16_t average = 0;  
  32.         
  33.     int i = 0;
  34.     for (i = 0; i < ZYB_BUF_LEN - 1; ++i)
  35.     {
  36.         buf[i] = buf[i+1];
  37.     }
  38.     buf[ZYB_BUF_LEN - 1] = val;

  39.     for (i = 0; i < ZYB_BUF_LEN; ++i)
  40.     {
  41.         sum += buf[i];
  42.     }
  43.     average = sum / ZYB_BUF_LEN;

  44.     return average;
  45. }
  46. /*
  47. *@function:zyb_current_check(void)
  48. *@brief:电流检测
  49. *@param:None
  50. *@retval:None
  51. */
  52. void zyb_current_check(void)
  53. {
  54.    
  55.     if(SystemStatus.zyb_mode != 0x00 || (SystemStatus.auto_clean))//2个条件:1:工作模式为1档或者二档出水 2:自清洗模式
  56.     {
  57.         if (TIMER_STOP == current_timer.timer_run_flag)
  58.         {
  59.             /* code */
  60.             current_timer.cnt = 0;
  61.             current_timer.timer_run_flag = TIMER_RUN;
  62.         }
  63.         else if (TIMER_END == current_timer.timer_run_flag)
  64.         {
  65.             current_timer.timer_run_flag = TIMER_STOP;

  66.             temp = Get_ADC_Convertion(ZYB_CURRENT);//ADC通道转换
  67.             temp1 = get_current_average_value(Current_Aver_Buf,temp);//电流平均值
  68.         }
  69.         /*增压泵空转检测,增压泵空转时间超过5s停止工作*/
  70.         if(zyb_timer.cnt >= 5000)
  71.         {            
  72.             if((SystemStatus.zyb_mode == 0x01) && (temp1 < 10))//50  水泵一档出水PWM占空比为50%
  73.             {
  74.                 zyb_timer.timer_run_flag = TIMER_STOP;
  75.                
  76.                 FSF_F2_OFF;
  77.                 JSF_F1_OFF;
  78.                 PSF_F3_OFF;
  79.                
  80.                 Close_ZYB();
  81.                
  82.                 SystemStatus.out = 0;
  83.                 SystemStatus.work_mode = 0;//0x00:停止出水  
  84.                 SystemStatus.zyb = 0;
  85.                
  86.                
  87.                 /*主控板部分如果增压泵空转5s则退出自清洗模式*/
  88.                
  89.                 if(SystemStatus.auto_clean)
  90.                 {
  91.                   SystemStatus.auto_clean = 0x00;
  92.                 }
  93.             }
  94.             else if((SystemStatus.zyb_mode == 0x02)&&(temp1 < 30))//100 水泵二档出水PWM占空比为100%,即全压输出
  95.             {
  96.                 zyb_timer.timer_run_flag = TIMER_STOP;
  97.                
  98.                 FSF_F2_OFF;
  99.                 JSF_F1_OFF;
  100.                 PSF_F3_OFF;

  101.                 Close_ZYB();
  102.                
  103.                 SystemStatus.out = 0;
  104.                 SystemStatus.work_mode = 0;
  105.                 SystemStatus.zyb = 0;
  106.                
  107.                 /*主控板部分如果增压泵空转5s则退出自清洗模式,自清洗是二档出水*/
  108.                 if(SystemStatus.auto_clean)
  109.                 {
  110.                   SystemStatus.auto_clean = 0x00;
  111.                 }
  112.                
  113.             }
  114.         }        
  115.     }   
  116. }



  117. /**
  118. *函数:Auto_Clean_proc
  119. *功能:自清洗进程,48小时如果没有任何操作,开始自清洗,按键无效
  120. *参数:无
  121. *返回值:无
  122. */

  123. void Auto_Clean_proc(void)
  124. {   
  125.     if(Auto_clean_timer.min >= 10)   //48小时自清洗,Auto_clean_timer.hour >= 48 改时间为30min
  126.     {     
  127.         SystemStatus.auto_clean = AUTO_CLEAN_STATUS;//自清洗为二档出水
  128.         
  129.         
  130.         
  131.       
  132.         
  133.     }        
  134.     if(SystemStatus.auto_clean && SystemStatus.outair)//自清洗中且不为自排气
  135.     {
  136.         static uint8_t old_status = 0;
  137.         
  138.         if(SystemStatus.auto_clean && old_status != SystemStatus.auto_clean)     //48小时自清洗
  139.         {      
  140.             PSF_F3_ON;  //排水阀-F3打开

  141.             JSF_F1_OFF; //进水阀-F1关闭

  142.             FSF_F2_OFF; //放水阀-F2关闭

  143.             ///Open_two_mode();     //水泵二档出水
  144.             Open_one_mode();//测试用一档出水
  145.          

  146.         }
  147.         SystemStatus.fullwater  = 0x00;
  148.         SystemStatus.makewater  = 0x00;
  149.         SystemStatus.work_mode  = 0x00;
  150.         old_status = SystemStatus.auto_clean;
  151.         

  152.         
  153.     }
  154.     if(TIMER_STOP == Auto_clean_timer.timer_run_flag)
  155.     {
  156.         Auto_clean_timer.timer_run_flag = TIMER_RUN;
  157.     }
  158.     if(SystemStatus.out || !SystemStatus.outair || SystemStatus.auto_clean)
  159.     {
  160.     //SystemStatus.auto_clean =0x00;
  161.         Auto_clean_timer.hour = 0 ;
  162.         Auto_clean_timer.min  = 0 ;
  163.         Auto_clean_timer.sec  = 0 ;
  164.         Auto_clean_timer.cnt  = 0 ;
  165.     }
  166.    
  167.    
  168. }



  169. /**
  170. *函数:HeartBeat_Send
  171. *功能:
  172. *参数:无
  173. *返回值:无
  174. */
  175. void HeartBeat_Send(void)
  176. {
  177.   
  178.     if(TIMER_STOP == HeartBeat_timer.timer_run_flag)
  179.     {
  180.         HeartBeat_timer.timer_run_flag = TIMER_RUN;
  181.         HeartBeat_timer.cnt = 1000;       //1s
  182.         
  183.         if(TIMER_RUN == HeartBeat_timer.timer_run_flag)
  184.         {
  185.             uint8_t buf[21] = "AA55";//
  186.             uint8_t crc_code = 0;
  187.             uint8_t i=0;
  188.             
  189.             buf[4] = (SystemStatus.tds / 16) ;       //tds
  190.             buf[4] = (buf[4] >= 0 &&buf[4]<=9)?buf[4]+'0':buf[4]+0x37;
  191.             buf[5] = (SystemStatus.tds % 16) ;
  192.             buf[5] = (buf[5] >= 0 &&buf[5]<=9)?buf[5]+'0':buf[5]+0x37;
  193.    
  194.             buf[6] = SystemStatus.out ? '1': '0';      //出水   
  195.             buf[7] = SystemStatus.fullwater&0x40? '1':'0';       //0x40缺水
  196.             buf[8] = SystemStatus.fullwater&0x20? '1':'0';        //0x20补水
  197.             buf[9] = SystemStatus.makewater ? '1': '0';         //制水模式
  198.             buf[10] = SystemStatus.uv ? '1': '0';               //uv         
  199.             buf[11] = SystemStatus.work_mode & 0x04 ? '1':'0';  //水泵工作模式:二档出水
  200.             buf[12] = SystemStatus.work_mode & 0x02 ? '1':'0';//水泵工作模式:一档出水      
  201.             buf[13] = SystemStatus.auto_clean ? '1': '0'; //
  202.             
  203.             //  buf[14] = 0;          //Ô¤Áôλ
  204.             //  buf[15] = 0;
  205.             buf[14] = SystemStatus.liquid_level ? '1': '0';
  206.             buf[15] = !SystemStatus.outair ? '1': '0';
  207.             buf[16] = SystemStatus.err_code ? '1': '0'; //错误码
  208.             
  209.                     
  210.             for(i=0;i<=16;i++)
  211.             {
  212.                 crc_code += buf[i];
  213.             }
  214.             buf[17] = (crc_code / 16);
  215.             buf[17] = (buf[17] >= 0 &&buf[17]<=9)?buf[17]+'0':buf[17]+0x37;
  216.             buf[18] = (crc_code % 16);
  217.             buf[18] = (buf[18] >= 0 &&buf[18]<=9)?buf[18]+'0':buf[18]+0x37;
  218.             buf[19] = '\r';
  219.             buf[20] = '\n';

  220.             //UART1_SendString(buf);
  221.             for(i=0;i<=20;i++)
  222.             {
  223.                 while((UART1->SR & UART1_FLAG_TXE)==RESET);
  224.                 UART1->DR = buf[i];
  225.                 while((UART1->SR & UART1_FLAG_TC)==RESET);
  226.             }
  227.         }
  228.     }
  229. }
复制代码






收藏 评论2 发布时间:2019-11-30 20:47

举报

2个回答
butterflyspring 回答时间:2019-12-10 16:41:23
可以将工作模式设置成一个变量1,2,3,4,5等代表不同的模式。达到必要条件时就修改成哪个模式
hejun96 回答时间:2020-1-26 20:20:28
butterflyspring 发表于 2019-12-10 16:41
可以将工作模式设置成一个变量1,2,3,4,5等代表不同的模式。达到必要条件时就修改成哪个模式 ...

是写成消息任务切换对吧
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版