返回列表 发布新帖

中型PLC常用ST指令_算术运算符

374 0
发表于 2024-7-10 18:16:53 | 查看全部 阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
<h3 style="overflow-wrap: break-word; margin: 0px 0px 16px; padding: 0px; font-size: 1.25em; line-height: 1.25; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; text-wrap: wrap; background-color: rgb(255, 255, 255);">1.2 算术运算符</h3><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><img src="/upload/image/20230621/1687340580737462.png" alt="" style="overflow-wrap: break-word; border: 0px; vertical-align: middle;"/></p><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);">算术运算符就是我们数学上的加减乘除,这里呢拿出来简单讲一下。会小学数学,就肯定会PLC编程中的加减乘除!</p><h4 style="overflow-wrap: break-word; margin: 0px 0px 16px; padding: 0px; font-size: 14px; line-height: 1.25; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; text-wrap: wrap; background-color: rgb(255, 255, 255);">1.2.1加法 +</h4><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);">在ST语法中,加法就是&quot;+&quot;数学上的加法符号。假如已知变量:<br/>vi_VarA := 10;<br/>vi_VarB := 90;<br/>则:vi_Num := vi_VarA + vi_VarB;<br/>经过运算,vi_Num输出值为 100;</p><h4 style="overflow-wrap: break-word; margin: 0px 0px 16px; padding: 0px; font-size: 14px; line-height: 1.25; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; text-wrap: wrap; background-color: rgb(255, 255, 255);">1.2.2减法 -</h4><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);">在ST语法中,减法就是“-”数学上的减号。假如已知变量:<br/>vi_VarA := 10;<br/>vi_VarB := 90;<br/>则:vi_Num := vi_VarA - vi_VarB;<br/>经过运算,vi_Num输出值为 -80;</p><h4 style="overflow-wrap: break-word; margin: 0px 0px 16px; padding: 0px; font-size: 14px; line-height: 1.25; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; text-wrap: wrap; background-color: rgb(255, 255, 255);">1.2.3 乘法 *</h4><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);">在ST语法中,乘法就是“<em style="overflow-wrap: break-word; color: rgb(102, 102, 102);">”星号。假如已知变量:<br/>//-----乘法的运用----------------------------<br/>vf_圆周率&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;:= 3.1415926;<br/>vi_半径&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;:= 8;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//----8mm<br/>vf_圆面积&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;:= vf_圆周率&nbsp;</em>INT_TO_REAL(vi_半径 * vi_半径);<br/>运算结果就是半径为8mm的圆面积。</p><h4 style="overflow-wrap: break-word; margin: 0px 0px 16px; padding: 0px; font-size: 14px; line-height: 1.25; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; text-wrap: wrap; background-color: rgb(255, 255, 255);">1.2.4 除法 /</h4><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);">ST语法中的除法就是&quot;/&quot;<br/>//-----已知 vf_圆周长 := 15mm,求直径.--------<br/>vf_圆周长&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;:= 15;<br/>vf_直径&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;:= vf_圆周长 / vf_圆周率;</p><h4 style="overflow-wrap: break-word; margin: 0px 0px 16px; padding: 0px; font-size: 14px; line-height: 1.25; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; text-wrap: wrap; background-color: rgb(255, 255, 255);">1.2.5 变量区代码:</h4><pre style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; background-color: rgb(246, 248, 250); border-radius: 6px; overflow: auto; padding: 4px; font-size: 12px; line-height: 1.45; color: rgb(51, 51, 51); border: none !important;">PROGRAM&nbsp;PLC_PRG
VAR
vi_VarA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;INT;
vi_VarB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;INT;
vi_Var1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;INT;
vi_Var2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;INT;
vf_圆周率&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;REAL;
vi_半径&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;INT;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//mm
vf_圆面积&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;REAL;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//mm^2
vf_圆周长&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;REAL;&nbsp;//mm
vf_直径:&nbsp;REAL;
END_VAR</pre><h4 style="overflow-wrap: break-word; margin: 0px 0px 16px; padding: 0px; font-size: 14px; line-height: 1.25; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; text-wrap: wrap; background-color: rgb(255, 255, 255);">1.2.6 程序段代码:</h4><pre style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; background-color: rgb(246, 248, 250); border-radius: 6px; overflow: auto; padding: 4px; font-size: 12px; line-height: 1.45; color: rgb(51, 51, 51); border: none !important;">vi_VarA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;10;
vi_VarB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;90;

//-----加法指令的运用,运算结果100-----------
vi_Var1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;vi_VarA&nbsp;+&nbsp;vi_VarB;

//-----减法指令的运用,运算结果-80-----------
vi_Var2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;vi_VarA&nbsp;-&nbsp;vi_VarB;

//-----乘法的运用----------------------------
vf_圆周率&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;3.1415926;
vi_半径&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;8;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//----8mm

vf_圆面积&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;vf_圆周率&nbsp;*&nbsp;INT_TO_REAL(vi_半径&nbsp;*&nbsp;vi_半径);

//-----除法的应用----------------------------
//-----已知&nbsp;vf_圆周长&nbsp;:=&nbsp;15mm,求直径.--------
vf_圆周长&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;15;
vf_直径&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;vf_圆周长&nbsp;/&nbsp;vf_圆周率;</pre><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);">程序运行结果<img src="/upload/image/20230621/1687340580828531.png" alt="" style="overflow-wrap: break-word; border: 0px; vertical-align: middle;"/></p><p style="overflow-wrap: break-word; margin-top: 0px; margin-bottom: 15px; padding: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><br/></p><p><br/></p>

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright © 2001-2025 英威腾技术论坛 版权所有 All Rights Reserved. 粤ICP备07504406号
关灯 在本版发帖
扫一扫添加微信客服
返回顶部
快速回复 返回顶部 返回列表