优化这段代码 if( i == 0 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdComPcl[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 1 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdComBaud[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 2 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszComParity[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 3 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszStateName1[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 13 || i == 14) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszPoint[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 15 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszData[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 16 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdJmMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 17 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdAreaMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 20 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdSynctmMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); } else if( i == 21 ) { LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdRSMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]); }
时间: 2023-12-10 18:42:18 浏览: 62
可以将这段代码进行优化,使用一个 switch case 语句来替代多个 if else 语句。具体实现代码如下:
```c
switch (i) {
case 0:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdComPcl[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 1:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdComBaud[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 2:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszComParity[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 3:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszStateName1[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 13:
case 14:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszPoint[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 15:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszData[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 16:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdJmMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 17:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdAreaMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 20:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdSynctmMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
case 21:
LCD_DisString_Not((i%9)+1, 15, (char *)gcszLcdRSMode[(int)gRunPara.COMMS_SerialInfo[serialid][i].val]);
break;
default:
break;
}
```
使用 switch case 语句可以让代码更加简洁明了,易于维护和修改。
阅读全文