当自定义2字节变量a为0时 自定义开关量bcd均为0 当a为1时 b为1 cd为0 当a为2时 c为1 bd为0 当 a为3时 d为1 bc为0 这个逻辑该怎么写 初学者急用 在线等财富值有限
增加了0~3以外的else,可以自行考虑。YB_G121A需要设置成整数(int)。
if YB_G121A=0 THEN
S7 = ON;
S8 = ON;
S9 = OFF;
ELSEIF YB_G121A=1 THEN
S7 = ON;
S8 = OFF;
S9 = OFF;
ELSEIF YB_G121A=2 THEN
S7 = OFF;
S8 = ON;
S9 = OFF;
ELSEIF YB_G121A=3 THEN
S7 = OFF;
S8 = OFF;
S9 = ON;
ELSE
S7 = OFF;
S8 = OFF;
S9 = OFF;
END_IF;
if YB_G121A=0 THEN
S7 = ON;
S8 = ON;
S9 = OFF;
ELSEIF YB_G121A=1 THEN
S7 = ON;
S8 = OFF;
S9 = OFF;
ELSEIF YB_G121A=2 THEN
S7 = OFF;
S8 = ON;
S9 = OFF;
ELSEIF YB_G121A=3 THEN
S7 = OFF;
S8 = OFF;
S9 = ON;
ELSE
S7 = OFF;
S8 = OFF;
S9 = OFF;
END_IF;
温馨提示:答案为网友推荐,仅供参考