优化这段代码 if( DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE) { LCD_DisString((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if(DBData[i] == RT1064KZZ_MODE) { LCD_DisString((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if (DBData[i] == RT1064KZZ_FBS || DBData[i] == RT1064KZZ_FBS_MODE ) { if (DBData[i] == RT1064KZZ_FBS) { LCD_DisString((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if(DBData[i] == RT1064KZZ_FBS_MODE ) { LCD_DisString((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } } else if(DBData[i] == RT1064KZZ_UAB_CH || DBData[i] == RT1064KZZ_UBC_CH || DBData[i] == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f" , get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])); LCD_DisString((i%9)+1, 19 , szVal); if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%9)+1, 24, (char *)"次"); if (not == 2) { if(draw == (i+1)) { len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); } } }
时间: 2024-02-03 08:11:38 浏览: 84
可以尝试使用 switch-case 语句替代多个 if-else,代码会更加简洁易懂。同时,对于重复的代码可以将其提取出来,避免代码冗余。例如,LCD_DisString 和 LCD_DisString_Not 的代码可以提取出来,避免重复编写。最后,可以考虑使用注释来解释代码的作用,增强代码可读性。以下是修改后的代码示例:
```
for(int i=0;i<RT1064KZZ_DZS;i++)
{
switch(DBData[i])
{
case RT1064KZZ_MODE:
LCD_DisString((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
if(not == 2 && draw == (i+1))
{
LCD_DisString_Not((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
}
break;
case RT1064KZZ_FBS:
LCD_DisString((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
if(not == 2 && draw == (i+1))
{
LCD_DisString_Not((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
}
break;
case RT1064KZZ_FBS_MODE:
LCD_DisString((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
if(not == 2 && draw == (i+1))
{
LCD_DisString_Not((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
}
break;
case RT1064KZZ_UAB_CH:
case RT1064KZZ_UBC_CH:
case RT1064_DZ_CHZCS:
sprintf(szVal, "%0.f" , get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i]));
LCD_DisString((i%9)+1, 19 , szVal);
if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%9)+1, 24, (char *)"次");
if(not == 2 && draw == (i+1))
{
len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit);
}
break;
default:
if(DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE)
{
LCD_DisString((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
if(not == 2 && draw == (i+1))
{
LCD_DisString_Not((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]);
}
}
break;
}
}
```
阅读全文