3262 views|0 replies

6

Posts

0

Resources
The OP
 

How to solve the problem that two mutually exclusive flags in the business logic code of STM8S003K3 both execute the same function [Copy link]

First of all, this is a program controlled by a faucet. The main control board reports data to the display screen driven by ht1621b through the serial port. The display screen will display different icons according to the serial port only after receiving the data from the serial port. The problematic program is attached below. First, after booting up, there is a touch IC button on the display screen, and the icons on the display screen flash in turn (this process is the faucet exhaust process) until the button is pressed for 10 seconds to exit the exhaust. After exiting the exhaust, the water can be discharged in first and second gears by the STM8S to control the booster pump IO port output (the first gear is the half-pressure output controlled by PWM, and the second gear is the full-pressure output). After the booster pump has no work for xmin (x represents the number of minutes), it enters the automatic flushing state. In this state, the booster pump can work in the first gear to clean the water in the water tank. There are two conditions for exiting: one is water shortage, and the other is that the water pump is idling for 5s. Now it can exit when there is water shortage, but the water pump idling for 5s collects data through AD current, but the conditions for exiting when the water pump is idling for 5s and water shortage are different, and SystemStatus.work_mode (working mode: first and second gear water discharge) and SystemStatus.auto_clean (self-cleaning mode flag) are mutually exclusive. SystemStatus.zyb_mode (boost pump is PWM half-pressure output or full-pressure output) belongs to a subset of SystemStatus.work_mode. I don't know how to execute both conditions, but the functions executed are similar. The problematic codes are written below, but I don't know how to solve them?

  1. * Main control board status information */
  2. typedef struct waterbox_info
  3. {
  4. uint8_t tds;
  5. uint16_t temperature;
  6. uint8_t out; //water 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; /*Error code: water leakage*/
  13. uint8_t crc_code;
  14. uint8_t outair; //Self-exhaust
  15. uint8_t isEmpty; //No water in the water tank
  16. uint8_t zyb;
  17. uint8_t liquid_level; //liquid level protect
  18. uint8_t leakwater; /*water leakage*/
  19. uint8_t jump_outair; //skip exhaust
  20. uint8_t zyb_mode;
  21. }System_t;
  22. /* Structure */
  23. System_t SystemStatus = {0};
  24. uint16_t Current_Aver_Buf[ZYB_BUF_LEN]={0}; //Boost pump average value buffer length
  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. int i = 0;
  33. for (i = 0; i < ZYB_BUF_LEN - 1; ++i)
  34. {
  35. buf[i] = buf[i+1];
  36. }
  37. buf[ZYB_BUF_LEN - 1] = val;
  38. for (i = 0; i < ZYB_BUF_LEN; ++i)
  39. {
  40. sum += buf[i];
  41. }
  42. average = sum / ZYB_BUF_LEN;
  43. return average;
  44. }
  45. /*
  46. *@function:zyb_current_check(void)
  47. * @brief: Current detection
  48. *@param:None
  49. * @retval:None
  50. */
  51. void zyb_current_check(void)
  52. {
  53. if(SystemStatus.zyb_mode != 0x00 || (SystemStatus.auto_clean)) //2 conditions: 1: working mode is 1st or 2nd gear water discharge 2: self-cleaning mode
  54. {
  55. if (TIMER_STOP == current_timer.timer_run_flag)
  56. {
  57. /* code */
  58. current_timer.cnt = 0;
  59. current_timer.timer_run_flag = TIMER_RUN;
  60. }
  61. else if (TIMER_END == current_timer.timer_run_flag)
  62. {
  63. current_timer.timer_run_flag = TIMER_STOP;
  64. temp = Get_ADC_Convertion(ZYB_CURRENT); //ADC channel conversion
  65. temp1 = get_current_average_value(Current_Aver_Buf,temp); // average current value
  66. }
  67. /*Booster pump idling detection, booster pump stops working if idling time exceeds 5s*/
  68. if(zyb_timer.cnt >= 5000)
  69. {
  70. if((SystemStatus.zyb_mode == 0x01) && (temp1 < 10)) //50 The PWM duty cycle of the first gear of the water pump is 50%
  71. {
  72. zyb_timer.timer_run_flag = TIMER_STOP;
  73. FSF_F2_OFF;
  74. JSF_F1_OFF;
  75. PSF_F3_OFF;
  76. Close_ZYB();
  77. SystemStatus.out = 0;
  78. SystemStatus.work_mode = 0; //0x00: stop discharging water
  79. SystemStatus.zyb = 0;
  80. /* If the booster pump runs idle for 5 seconds, the main control board will exit the self-cleaning mode*/
  81. if(SystemStatus.auto_clean)
  82. {
  83. SystemStatus.auto_clean = 0x00;
  84. }
  85. }
  86. else if((SystemStatus.zyb_mode == 0x02)&&(temp1 < 30))//100 The PWM duty cycle of the second-gear water discharge of the water pump is 100%, that is, full pressure output
  87. {
  88. zyb_timer.timer_run_flag = TIMER_STOP;
  89. FSF_F2_OFF;
  90. JSF_F1_OFF;
  91. PSF_F3_OFF;
  92. Close_ZYB();
  93. SystemStatus.out = 0;
  94. SystemStatus.work_mode = 0;
  95. SystemStatus.zyb = 0;
  96. /* If the booster pump runs idle for 5 seconds, the main control board will exit the self-cleaning mode, and the self-cleaning mode is the second gear water output*/
  97. if(SystemStatus.auto_clean)
  98. {
  99. SystemStatus.auto_clean = 0x00;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. /**
  106. *Function: Auto_Clean_proc
  107. *Function: Self-cleaning process, if there is no operation for 48 hours, it will start self-cleaning and the button will be invalid
  108. *Parameters: None
  109. *Return value: None
  110. */
  111. void Auto_Clean_proc(void)
  112. {
  113. if(Auto_clean_timer.min >= 10) //48 hours of self-cleaning, Auto_clean_timer.hour >= 48, change the time to 30min
  114. {
  115. SystemStatus.auto_clean = AUTO_CLEAN_STATUS; // Self-cleaning is the second gear water output
  116. }
  117. if(SystemStatus.auto_clean && SystemStatus.outair) //Self-cleaning and not self-exhausting
  118. {
  119. static uint8_t old_status = 0;
  120. if(SystemStatus.auto_clean && old_status != SystemStatus.auto_clean) //48 hours self-cleaning
  121. {
  122. PSF_F3_ON; //Drain valve-F3 open
  123. JSF_F1_OFF; //Water inlet valve-F1 closed
  124. FSF_F2_OFF; //Drain valve-F2 is closed
  125. ///Open_two_mode(); //Water pump discharges water in second gear
  126. Open_one_mode(); //Test with one mode of water output
  127. }
  128. SystemStatus.fullwater = 0x00;
  129. SystemStatus.makewater = 0x00;
  130. SystemStatus.work_mode = 0x00;
  131. old_status = SystemStatus.auto_clean;
  132. }
  133. if(TIMER_STOP == Auto_clean_timer.timer_run_flag)
  134. {
  135. Auto_clean_timer.timer_run_flag = TIMER_RUN;
  136. }
  137. if(SystemStatus.out || !SystemStatus.outair || SystemStatus.auto_clean)
  138. {
  139. //SystemStatus.auto_clean =0x00;
  140. Auto_clean_timer.hour = 0;
  141. Auto_clean_timer.min = 0;
  142. Auto_clean_timer.sec = 0 ;
  143. Auto_clean_timer.cnt = 0;
  144. }
  145. }
  146. /**
  147. * Function: HeartBeat_Send
  148. *Function:
  149. *Parameter: None
  150. *Return value: None
  151. */
  152. void HeartBeat_Send(void)
  153. {
  154. if(TIMER_STOP == HeartBeat_timer.timer_run_flag)
  155. {
  156. HeartBeat_timer.timer_run_flag = TIMER_RUN;
  157. HeartBeat_timer.cnt = 1000; //1s
  158. if(TIMER_RUN == HeartBeat_timer.timer_run_flag)
  159. {
  160. uint8_t buf[21] = "AA55"; //
  161. uint8_t crc_code = 0;
  162. uint8_t i=0;
  163. buf[4] = (SystemStatus.tds / 16); //tds
  164. buf[4] = (buf[4] >= 0 &&buf[4]<=9)?buf[4]+'0':buf[4]+0x37;
  165. buf[5] = (SystemStatus.tds % 16);
  166. buf[5] = (buf[5] >= 0 &&buf[5]<=9)?buf[5]+'0':buf[5]+0x37;
  167. buf[6] = SystemStatus.out ? '1': '0'; //Water out
  168. buf[7] = SystemStatus.fullwater&0x40? '1':'0'; //0x40 is short of water
  169. buf[8] = SystemStatus.fullwater&0x20? '1':'0'; //0x20 water replenishment
  170. buf[9] = SystemStatus.makewater ? '1': '0'; //Water making mode
  171. buf[10] = SystemStatus.uv ? '1': '0'; //uv
  172. buf[11] = SystemStatus.work_mode & 0x04 ? '1':'0'; //Water pump working mode: second gear water discharge
  173. buf[12] = SystemStatus.work_mode & 0x02 ? '1':'0'; //Water pump working mode: first gear water discharge
  174. buf[13] = SystemStatus.auto_clean ? '1': '0'; //
  175. // buf[14] = 0; //¤á
  176. // buf[15] = 0;
  177. buf[14] = SystemStatus.liquid_level ? '1': '0';
  178. buf[15] = !SystemStatus.outair ? '1': '0';
  179. buf[16] = SystemStatus.err_code ? '1': '0'; //Error code
  180. for(i=0;i<=16;i++)
  181. {
  182. crc_code += buf[i];
  183. }
  184. buf[17] = (crc_code / 16);
  185. buf[17] = (buf[17] >= 0 &&buf[17]<=9)?buf[17]+'0':buf[17]+0x37;
  186. buf[18] = (crc_code % 16);
  187. buf[18] = (buf[18] >= 0 &&buf[18]<=9)?buf[18]+'0':buf[18]+0x37;
  188. buf[19] = '\r';
  189. buf[20] = '\n';
  190. //UART1_SendString(buf);
  191. for(i=0;i<=20;i++)
  192. {
  193. while((UART1->SR & UART1_FLAG_TXE)==RESET);
  194. UART1->DR = buf[i];
  195. while((UART1->SR & UART1_FLAG_TC)==RESET);
  196. }
  197. }
  198. }
  199. }
This post is from stm32/stm8
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list