CPM2A_PROGRAMMING MANUAL (W353-E1-2) (986750), страница 25
Текст из файла (страница 25)
A number of similar program sections can bemanaged with just one subroutine, thereby greatly reducing the number of stepsin the program and making the program easier to understand.Using MacrosTo use a macro, call a subroutine by means of the MACRO instruction,MCRO(99), as shown below, in stead of SBS(91) (SUBROUTINE ENTRY).MCRO(99)Subroutine NoFist input wordFirst output wordWhen MCRO(99) is executed, operation will proceed as follows:1, 2, 3...1. The contents of the four consecutive words beginning with the first inputword will be transferred to SR 232 through SR 235.2. The specified subroutine will be executed until RET(93) (Subroutine Return)is executed.3. The contents of SR 236 through SR 239 (results of the subroutine execution) will be transferred to the four consecutive words beginning with the firstoutput word.4.
MCRO(99) will then be finished.When MCRO(99) is executed, the same instruction pattern can be used asneeded simply by changing the first input word or the first output word.The following restrictions apply when the macro function is used.• The only words that can be used for each execution of the macro are the fourconsecutive words beginning with the first input word number (for input) andthe four consecutive words beginning with the first output word (for output).• The specified inputs and outputs must correctly correspond to the words usedin the subroutine.• Even when the direct output method is used for outputs,subroutine results willbe actually reflected in the specified output words only when the subroutinehas been completed (step 3 above).Note SR 232 through SR 239 can be used as work bits when MCRO(99) is not used.The first input word and the first output word can be specified not with I/O bits, butalso with other bits (such as HR bits, work bits, etc.) or with DM words.Subroutines called by MCRO(99) are defined by SBN(92) and RET(93), just asare ordinary subroutines.145Section 2-16Calculating with Signed Binary DataApplication ExampleWhen a macro is used, the program can be simplified as shown below.Macro not usedMacro used25313 (Always ON)0000020001MCRO(99)20000030000200002000000100002MCRO(99)20001002000300022050120520500MCRO(99)2050003000201005002022050100500210MCRO(99)2100121000030010210002200050100502SBN(92)210010100023200220012360123600220002360022000001010300010222001Subroutine usedto define macro232012320223201RET(93)2-16 Calculating with Signed Binary DataThe CPM1/CPM1A/CPM2A/SRM1(-V2) allow calculations on signed binarydata.
The following instructions manipulate signed binary data. Signed data ishandled using 2’s complements.CPM2A/CPM2C andSRM1(-V2) InstructionsThe following signed-binary instructions are available in CPM2A, CPM2C, andSRM1(-V2) PCs:• BINARY ADD – ADB(50)• BINARY SUBTRACT – SBB(51)• 2’S COMPLEMENT – NEG(––)CPM1/CPM1A InstructionsThe following signed-binary instructions are available in CPM1/CPM1A PCs:• BINARY ADD – ADB(50)• BINARY SUBTRACT – SBB(51)Signed Data Calculations146AdditionSubtraction7 + 3 = 107–3=4(–7) + 3 = –4(–7) – 3 = –107 + (–3) = 47 – (–3) = 10(–7) + (–3) = –10(–7) – (–3) = –4Section 2-17Differential Monitor2-16-1 Definition of Signed Binary DataSigned binary data is manipulated using 2’s complements and bit 15 is used asthe sign bit.
The range of data that can be expressed using one word is as follows:–32,768 to 32,767 (8000 to 7FFF hexadecimal).The following table shows equivalents between decimal and hexadecimal data.Decimal32,76732,766...210–1–2...–32,767–32,7684-digit Hexadecimal7FFF7FFE...000200010000FFFFFFFE...800180002-16-2 Arithmetic FlagsThe results of executing signed binary instructions is reflected in the arithmeticflags. The flags and the conditions under which it will turn ON are given in thefollowing table.
The flags will be OFF when these conditions are not met.FlagCarry Flag (SR 25504)ON conditionsCarry in an addition.Negative results for subtraction.Equals Flag (SR 25506)The results of addition, subtraction,multiplication, or division is 0.Results of converting 2’s complement is 0.2-16-3 Inputting Signed Binary Data Using Decimal ValuesAlthough calculations for signed binary data use hexadecimal expressions, inputs from the Programming Console or SSS can be done using decimal inputsand mnemonics for the instructions.
The procedure to using the ProgrammingConsole to input using decimal values is shown in the CPM1 Operation Manual,CPM1A Operation Manual, CPM2A Operation Manual, CPM2C OperationManual, and SRM1 Master Control Unit Operation Manual. Refer to the SSS Operation Manual: C-series PCs for details on using the SSS.Inputting InstructionsRefer to the CPM1 Operation Manual, CPM1A Operation Manual, CPM2C Operation Manual, CPM2A Operation Manual, and SRM1 Master Control Unit Operation Manual details on inputting instructions from the Programming Console.2-17 Differential MonitorThe CPM1/CPM1A, CPM2A//CPM2C, and SRM1(-V2) support differentialmonitoring from either the Programming Console or the SSS.
The operator candetect on OFF-to-ON or ON-to-OFF transition in a specified bit. When the specified transition takes place, the transition is indicated on the display and a buzzersounds to enable easy recognition of the transition.Refer to the CPM1 Operation Manual, CPM1A Operation Manual, CPM2A Operation Manual, CPM2C Operation Manual, or SRM1 Master Control Units Operation Manual for details on the Programming Console Differential Monitor procedure and to the SSS Operation Manual: C-series PCs for the SYSMAC Support Software procedure.147Section 2-18Expansion Instructions (CPM2A/CPM2C/SRM1(-V2) Only)2-18 Expansion Instructions (CPM2A/CPM2C/SRM1(-V2) Only)A set of expansion instructions is available for the CPM2A, CPM2C, andSRM1(-V2) to aid in special programming needs.
Function codes can be assigned to up to 18 of the expansion instructions to enable using them in programs. This allows the user to pick the instructions needed by each CPM2A,CPM2C, or SRM1(-V2) program to more effectively use the function codes required to input instructions.The mnemonics of expansion instructions are followed by “(––)” as the functioncode to indicate that they must be assigned function codes by the user in theinstructions table before they can be used in programming (unless they are usedunder their default settings).Any of the instructions not assigned function codes will need to be assignedfunction codes in the instructions table used by the Programming Device and theCPM2A/CPM2C or SRM1(-V2) before they can be used in programming.
Theassignments of expansion instructions in the instructions table will change themeaning of instructions and operands, so be sure to set the instructions tablebefore programming and transfer the proper instructions table to the CPM2A/CPM2C or SRM1(-V2) before program execution.Example: CPM2A/CPM2C PCsThe specific instructions used in the following example are for the CPM2A/CPM2C. The concepts are the same for the SRM1(-V2).Function code 61INIFunction code 61SPEDSPEDFunction code 64PULSFunction code 64MINSUMAt the time of shipping, the function codes areassigned as shown above. (In this example,the instructions all relate to pulse outputs.)Note148PULSMAXMAXFunction code 65INIFunction code 65MINSUMIf pulse outputs are not being used, and ifmaximum values, minimum values, andsums are required, then the Set Instructionsoperation can be used as shown above toreassign instructions in the instruction table.1.
Set the PC model to “CQM1” when setting the expansion instructions for theSRM1(-V2) or CPM2A/CPM2C from the SSS.2. The PC Setup must be set for user-defined expansion instruction functioncodes in order for function codes to be assigned. Set bits 08 to 11 ofDM 6602 to 1.Expansion Instructions (CPM2A/CPM2C/SRM1(-V2) Only)Section 2-182-18-1 CPM2A/CPM2C Expansion InstructionsThe following 18 function codes can be used for expansion instructions: 17, 18,19, 47, 48, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 87, 88, and 89. The functioncode assignments can be changed with a Programming Console or the SupportSoftware.Refer to 4-4-5 Assigning Expansion Instruction Function Codes in the CPM2A orCPM2C Operation Manual for the Programming Console procedure.Refer to the SSS Operation Manual: C-series PCs for the SSS procedure.Refer to the SYSMAC-CPT Support Software Quick Start Guide (W332) andUser Manual (W333) for the SYSMAC-CPT Support Software procedure.The expansion instructions that can be used are listed below, along with the default function codes that are assigned when the PC is shipped.MnemonicASFT----RXDTXDCMPLINIPRVCTBLSPEDPULSSCLBCNTBCMPSTIM----INTACCAVGFCSHEXHMSMAXMINNEGPIDPWMSCL2SCL3SECSRCHSTUPSUMSYNCTIMLTMHHZCPZCPLFunction code171819474860616263646566676869878889-------------------------------------------149Expansion Instructions (CPM2A/CPM2C/SRM1(-V2) Only)Section 2-182-18-2 SRM1(-V2) Expansion InstructionsThe following 18 function codes can be used for expansion instructions: 17, 18,19, 47, 48, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 87, 88, and 89.
The functioncode assignments can be changed with a Programming Console or the SupportSoftware.Refer to 4-2-6 Setting Expansion Instructions in the SRM1 Master Control UnitOperation Manual for the Programming Console procedure.
Refer to the SSSOperation Manual: C-series PCs for the SSS procedure. Refer to the SYSMACCPT Support Software Quick Start Guide (W332) and User Manual (W333) forthe SYSMAC-CPT Support Software procedure.The expansion instructions that can be used are listed below, along with the default function codes that are assigned when the SRM1(-V2) is shipped.MnemonicFunction codeASFT-----171819RXD47TXD48CMPL-----------606162636465SCL*66BCNT67BCMP68STIM-------69878889FCS---HEX---NEG*---PID*---STUP---ZCP*---Note *SCL(66), NEG(––), PID(––), and ZCP (––) are supported by theSRM1-C0-V2 CPUs only.150Section 2-19Using the CPM2A/CPM2C Clock Function2-19 Using the CPM2A/CPM2C Clock FunctionThe CPM2A PCs and some CPM2C PCs have a built-in clock function.
This section explains how to use the clock.2-19-1 Data Area WordsThis following illustration shows the configuration of the words (AR 17 throughAR 21) that are used with the clock. These words can be read and used as required. (AR 17 is provided so that the hour and minute can be accessed quickly.)15AR 17AR 18AR 19AR 20AR 21HourMinuteDateYear8 70MinuteSecondHourMonthDay of week2 digits BCD each.(Only the last 2 digits of theyear are given.)00 to 06: Sunday to SaturdayAR 2115 Clock Set BitAR 2114 Clock Stop BitAR 2113 30-Second Adjustment Bit2-19-2 Setting the TimeTo set the time, use a programming device as follows:Setting Everything1, 2, 3...1. Turn ON AR 2114 (Clock Stop Bit) to stop the clock and allow AR 18 throughAR 21 to be overwritten.2. Using a Programming Device, set AR 18 through AR 20 (minute/second,date/hour, and year/month) and AR 2100 through AR 2107 (day of week).3.