1STLanguageBasicCourse2STLanguageKeywordIfthereisanyunclearoruncorrected,pleasefeelfreetospeakoutBasicCourse3RequirementsHardwareTheprogramminglanguageSTisonlyavailableforfollowingprogrammablecontrollers:•pCO3•Supernode•pCO5•pCOcompactBIOSTosupportSTlanguage,biosversionmustgreaterthan5.0SoftwareUseaversionof1tool=2.1.xpCO3pCO5Supernode4CreationofasolutionSTLanguageChoosing:-FBD,theapplicationwillbe'mixed’,itwillconsistofamainwithAtoms,Macroblocks...butyoucanuseroutines(functionsandfunctionblocks)writtenintheST-ST,theapplicationwillbedevelopedentirelyusing‘STlanguage’5BasicconceptsWhenprogramminginST,theapplicationcanbeorganisedusingthreefundamentalprogrammingelementsgenericallycalled‘ProgramOrganizationUnits’(POU):•PROGRAM•FUNCTION•FUNCTIONBLOCKPOUtypeKeywordDescriptionProgramPROGRAMmainEND_PROGRAMMainprogramthatincludes:read/writeI/OdefinitionoflocalvariablescallstoFunctionsorFunctionBlocksFunctionFUNCTIONEND_FUNCTIONSTstatementsblockwithinputvariables,localvariables,andifspecifiedareturnvalue.Thiscanbecalledatdifferentpointsoftheprogram.Recursionisnotallowed.FunctionblockFUNCTION_BLOCKEND_FUNCTION_BLOCKSTstatementsblockwithinputvariables,localvariables,andoutputvariables.Thiscanbecalledatdifferentpointsoftheprogram.Recursionisnotallowed.POUNote:wecandefinemorefunctionsandfunctionblocks,butonlyoneprogrammain6ThebasictypesKeywordDatatypeLowerlimitUpperlimitMemorySpaceBOOLBooleanFALSE(0)TRUE(1)8BitBYTEBitstring02558BitWORDBitstring06553516BitDWORDBitstring04.294.967.29532BitSINTShortInteger-1281278BitUSINTUnsignedShortInteger02558BitINTInteger-327683276716BitUINTUnsignedInteger06553516BitDINTDoubleInteger-2^31(2^31)-132BitUDINTUnsignedDoubleInteger02^32-132BitREALRealNumber-10^3810^3832BitBitstringIntegersThefollowingtablelistsallthepropertiesofbasictypes(IECType):7DeclarationofGlobalvariablesTherearetwowaystodeclareGlobalvariables:•‘VariableList’•‘Textualmode’ofSTlanguageButton‘User’Button‘Extend’‘IECType’•BOOL•INT•…•REAL‘IECType’•BOOL•INT•…•REALVariableListTextualmode‘CarelType’•Boolean•Integer/AnalogGlobalvariablesdeclarationUsableinanyenvironmentUsableonlyintheStrategyEditorST(no:MASK,FBDStrategyEditor)Youdon’tseethesevariablesinVariableListNote:ifyouwanttoseethevariableinthepGD,pleasedeclarethevariableintheVariableList8Assignmentoperator:=SyntaxAssigntoavariable:Inassignmentoperations“:=”thevariablesinvolvedmustallbethesametype,eachstatementmustuse“;”asthestatementterminator.InassignmentoperationswithBOOLvalues,1orTRUE,or0orFALSEcanbeusedindifferently.•aconstantvalue•thevalueofanothervariable•theresultofanexpression.Varaible_name:=expression;AssignmentoperatorStatementterminatorNote:thereisa;intheendofstatement9TextualdeclarationTodeclarevariablesinSTyouhavetousethefollowing‘declarationblock’:GlobalvariablesdeclaredintextmodewillnotbevisibleintheVariableList.TypeSyntaxDescritionGloabalVAR_GLOBALEND_VARDeclaresagroupofglobalvariables,sharedbyprogram,functionsorfunctionblocks.LocalVAREND_VARDeclaresagroupoflocalvariablestoaprogram,functionorfunctionblock.Note:1.thereisno;intheendofEND_VAR;2.wecangivethedefaultvalueinthedeclaration.10Rulesoftheidentifiers(variablesname)•‘a’..‘z’,‘A’..‘Z’•‘0’..‘9’•‘_’ValididentifiersInvalididentifiersNoteMn22MnThe1stcharactermustnotbenumeric._3exit_3exit.1“.”isnotincludedinthesetofcharacters.Enrg_offEnrgoffSpacesarenotallowed._Drill__DrillOnlysingleunderscores“_”areallowed.Valve,VALVENotcase-sensitive.Thevariablenamesarenotcase-sensitive‘Valve’,‘VaLVe’e‘VALVE’arethesamevariable.Thenameofanidentifier(variableorconstant)canbeanycombination(seeExample)ofthecharacterslistedbelow:ExampleRulestocreateidentifiers.11ThequalifierCONSTANTTextualdeclarationofConstants•ThekeywordCONSTANTcandeclareaconstant.•Theconstantsdonotoccupyspaceinmemoryasthevariables•Duringcompilationinsteadoftheconstantisreplacedanumericvalue.TypeSyntaxDescriptionCostantiLocaliVARCONSTANTEND_VARDeclaresagroupoflocalconstantstoaprogram,functionorfunctionblock.CostantiGlobaliVAR_GLOBALCONSTANTEND_VARDeclaresagroupofglobalconstants,sharedbyprogram,functionsorfunctionblocks.12CommentsCommentusingkeyword{REGION…ENDREGION}•Youcanhideseverallinesofcodeusingthekeyword{REGION…ENDREGION}.•Soincreasethereadabilityofthecodeonthescreen.•Thecodeisreplacedwithacomment.•Clickingoncommentitwillappearagainthecode.Thecodecomments•Youcanusetwowaystomakeacomment-Tocommentasinglecodelineuse“\\”-Tocommentmorecodelinesuse“(*”and“*)”Thereisno_inbetweenENDandREGION13ThequalifierRETAINTextualdeclarationofglobalvariablesREATAIN(retentive)ExampleDeclarationofretentiveGlobalvariables.RETAINkeyworddeclaresavariableinT-permanentmemory.TypeSyntaxDescriptionGlobalRetentiveVAR_GLOBALRETAINEND_VARDeclaresagroupofretainglobalvariables,sharedbyprogram,functionsorfunctionblocks.Itisnotpossibletoinitializearetainvariabletoadefaultvalueatthetimeofdeclaration.TheinitialisationofavariableinT-memorymustbeperformedusingtheVariableWizard,whichimpliescreationofthe.DEVfile.Organizationofthevariables.Note:payattentionofthedefaultvalue14CastFunctionsSyntax