advertisement
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT) Chapter 7
Swap Byte (SWPB)
Operands:
The SWPB instruction rearranges the bytes of a value.
Relay Ladder
Operand
Source
Type
INT
DINT
REAL
Format
tag
Enter
tag that contains the bytes that you want to rearrange
Order Mode
Destination INT
DINT
REAL tag
If the Source
Is an
And You Want To Change the Bytes To
This Pattern (Each Letter Represents a
Different Byte)
INT
DINT
REAL n/a
ABCD
⇒
ABCD
⇒
ABCD
⇒ tag to store the bytes in the new order
If the Source
Is an
Then the Destination Must Be an
INT INT
DINT
REAL
DINT
DINT
REAL
Then Select
any of the options
REVERSE (or enter 0)
WORD (or enter 1)
HIGH/LOW (or enter 2)
Structured Text
SWPB(Source,OrderMode,Dest);
The operands are the same as those for the relay ladder SWPB instruction. If you select the HIGH/LOW order mode, enter it as HIGHLOW or
HIGH_LOW (without the slash).
Publication 1756-RM003K-EN-P - July 2008
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com
299
Chapter 7 Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT) bar code reader
B A
42969
42968
A B
Arithmetic Status Flags:
not affected
Fault Conditions:
none
Execution:
Condition
prescan rung-condition-in is false rung-condition-in is true
EnableIn is set
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to true.
na instruction execution postscan
Description:
The SWPB instruction rearranges the order of the bytes of the Source. It places the result in the Destination.
When you read or write ASCII characters, you typically do not need to swap characters. The ASCII read and write instructions (ARD, ARL, AWA, AWT) automatically swap characters, as shown below.
The instruction rearranges the specified bytes.
The rung-condition-out is set to false.
Tag Name
bar_code[0]
Value Style Type
AB ASCII INT
Structured Text Action
No action taken na na
EnableIn is always set.
The instruction executes.
The instruction rearranges the specified bytes.
No action taken.
300
Publication 1756-RM003K-EN-P - July 2008
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT) Chapter 7
Example 1:
The three SWPB instructions each reorder the bytes of DINT_1 according to a different order mode. The display style is ASCII, and each character represents one byte. Each instruction places the bytes, in the new order, in a different Destination.
Relay Ladder
Structured Text
SWPB(DINT_1,REVERSE,DINT_1_reverse);
SWPB(DINT_1,WORD,DINT_1_swap_word);
SWPB(DINT_1,HIGHLOW,DINT_1_swap_high_low);
Example 2:
The following example reverses the bytes in each element of an array. For an
RSLogix 5000 project that contains this example, open the
RSLogix 5000\Projects\Samples folder, Swap_Bytes_in_Array.ACD file.
1.
Initialize the tags. The SIZE instruction finds the number of elements in
array and stores that value in array_length. A subsequent instruction uses this value to determine when the routine has acted on all the elements in the array.
2.
Reverse the bytes in one element of array.
•
The SWPB instruction reverses the bytes of the element number that is indicated by the value of index. For example, when index equals 0, the
SWPB instruction acts on array[0].
•
The ADD instruction increments index. The next time the instruction executes, the SWPB instruction acts on the next element in array.
3.
Determine when the SWPB instruction has acted on all the elements in the array.
•
If index is less then the number of elements in the array (array_length), then continue with the next element in the array.
•
If index equals array_length, then the SWPB has acted on all the elements in the array.
Publication 1756-RM003K-EN-P - July 2008
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com
301
Chapter 7 Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Relay Ladder
Initialize the tags.
Reverse the bytes.
Determine whether the SWPB instruction has acted on all the elements in the array.
Structured Text
index := 0;
SIZE (array[0],0,array_length);
REPEAT
SWPB(array[index],REVERSE,array_bytes_reverse[index]); index := index + 1;
UNTIL(index >= array_length)END_REPEAT;
302
Publication 1756-RM003K-EN-P - July 2008
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com
advertisement
Related manuals
advertisement
Table of contents
- 24 Introduction
- 24 Who Should Use This Manual
- 25 Purpose of This Manual
- 26 Common Information for All Instructions
- 26 Conventions and Related Terms
- 26 Set and clear
- 27 Relay ladder rung condition
- 28 Function block states
- 30 Introduction
- 31 Digital Alarm (ALMD)
- 37 State Diagrams when Acknowledgement Required
- 38 State Diagrams when Acknowledgment Not Required
- 39 ALMD Alarm Acknowledge Required and Latched
- 40 ALMD Alarm Acknowledge Required and Not Latched
- 40 ALMD Alarm Acknowledge Not Required and Latched
- 41 ALMD Alarm Acknowledge Not Required and Not Latched
- 43 Analog Alarm (ALMA)
- 55 State Diagrams when Acknowledgement Required
- 56 State Diagrams when Acknowledgement Not Required
- 59 ALMA Level Condition Acknowledge Required
- 60 ALMA Level Condition Acknowledge Not Required
- 61 ALMA Rate of Change Acknowledge Required
- 62 ALMA Rate of Change Acknowledge Not Required
- 64 Configure an Alarm Instruction
- 66 Enter Alarm Message Text
- 68 Message String Variables
- 69 Multiple Language Versions of Alarm Messages
- 70 Monitor Alarm Status
- 70 Buffering Alarms
- 71 Programmatically Access Alarm Information
- 72 Suppress or Disable Alarms
- 73 Controller-based Alarm Execution
- 74 Controller Memory Use
- 76 Scan Time
- 78 Introduction
- 79 Examine If Closed (XIC)
- 81 Examine If Open (XIO)
- 83 Output Energize (OTE)
- 85 Output Latch (OTL)
- 87 Output Unlatch (OTU)
- 89 One Shot (ONS)
- 92 One Shot Rising (OSR)
- 95 One Shot Falling (OSF)
- 97 One Shot Rising with Input (OSRI)
- 100 One Shot Falling with Input (OSFI)
- 104 Introduction
- 105 Timer On Delay (TON)
- 109 Timer Off Delay (TOF)
- 113 Retentive Timer On (RTO)
- 117 Timer On Delay with Reset (TONR)
- 121 Timer Off Delay with Reset (TOFR)
- 125 Retentive Timer On with Reset (RTOR)
- 129 Count Up (CTU)
- 133 Count Down (CTD)
- 137 Count Up/Down (CTUD)
- 142 Reset (RES)
- 144 Introduction
- 145 Message (MSG)
- 153 MSG Error Codes
- 153 Error Codes
- 155 Extended Error Codes
- 157 PLC and SLC Error Codes (.ERR)
- 159 Block-Transfer Error Codes
- 160 Specify the Configuration Details
- 161 Specify CIP Data Table Read and Write messages
- 162 Reconfigure an I/O module
- 163 Specify CIP Generic messages
- 164 Specify PLC-5 messages
- 166 Specify SLC messages
- 166 Specify block-transfer messages
- 167 Specify PLC-3 messages
- 168 Specify PLC-2 messages
- 169 MSG Configuration Examples
- 170 Specify the Communication Details
- 170 Specify a path
- 173 For Block Transfers
- 173 Specify a Communication Method Or Module Address
- 174 Choose a cache option
- 176 Guidelines
- 177 Get System Value (GSV) and Set System Value (SSV)
- 180 GSV/SSV Objects
- 181 Access the CONTROLLER object
- 182 Access the CONTROLLERDEVICE object
- 184 Access the CST object
- 185 Access the DF1 object
- 188 Access the FAULTLOG object
- 189 Access The MESSAGE Object
- 191 Access The MODULE Object
- 192 Access The MOTIONGROUP Object
- 193 Access The PROGRAM Object
- 194 Access The Routine object
- 194 Access The SERIALPORT Object
- 196 Access The TASK Object
- 198 Access The WALLCLOCKTIME Object
- 199 GSV/SSV Programming Example
- 199 Get Fault Information
- 201 Set Enable And Disable Flags
- 202 Immediate Output (IOT)
- 206 Introduction
- 207 Compare (CMP)
- 209 CMP expressions
- 209 Valid operators
- 210 Format Expressions
- 210 Determine The Order of Operation
- 211 Use Strings In an Expression
- 212 Equal to (EQU)
- 216 Greater than or Equal to (GEQ)
- 220 Greater Than (GRT)
- 224 Less Than or Equal to (LEQ)
- 228 Less Than (LES)
- 232 Limit (LIM)
- 238 Mask Equal to (MEQ)
- 239 Entering an Immediate Mask Value
- 243 Not Equal to (NEQ)
- 248 Introduction
- 249 Compute (CPT)
- 251 Valid operators
- 251 Format Expressions
- 252 Determine the order of operation
- 253 Add (ADD)
- 256 Subtract (SUB)
- 259 Multiply (MUL)
- 262 Divide (DIV)
- 267 Modulo (MOD)
- 271 Square Root (SQR)
- 275 Negate (NEG)
- 278 Absolute Value (ABS)
- 282 Introduction
- 284 Move (MOV)
- 286 Masked Move (MVM)
- 287 Enter an immediate mask value
- 289 Masked Move with Target (MVMT)
- 292 Bit Field Distribute (BTD)
- 295 Bit Field Distribute with Target (BTDT)
- 298 Clear (CLR)
- 300 Swap Byte (SWPB)
- 304 Bitwise AND (AND)
- 307 Bitwise OR (OR)
- 311 Bitwise Exclusive OR (XOR)
- 315 Bitwise NOT (NOT)
- 318 Boolean AND (BAND)
- 321 Boolean OR (BOR)
- 324 Boolean Exclusive OR (BXOR)
- 327 Boolean NOT (BNOT)
- 330 Introduction
- 331 Selecting Mode of Operation
- 331 All mode
- 332 Numerical mode
- 334 Incremental mode
- 336 File Arithmetic and Logic (FAL)
- 345 FAL Expressions
- 345 Valid operators
- 346 Format Expressions
- 346 Determine the order of operation
- 347 File Search and Compare (FSC)
- 352 FSC expressions
- 353 Valid Operators
- 353 Format Expressions
- 354 Determine the order of operation
- 355 Use Strings In an Expression
- 356 Copy File (COP) Synchronous Copy File (CPS)
- 362 File Fill (FLL)
- 366 File Average (AVE)
- 371 File Sort (SRT)
- 376 File Standard Deviation (STD)
- 382 Size In Elements (SIZE)
- 386 Introduction
- 387 Bit Shift Left (BSL)
- 391 Bit Shift Right (BSR)
- 395 FIFO Load (FFL)
- 401 FIFO Unload (FFU)
- 407 LIFO Load (LFL)
- 413 LIFO Unload (LFU)
- 420 Introduction
- 421 Sequencer Input (SQI)
- 422 Enter an Immediate Mask Value
- 424 Use SQI without SQO
- 425 Sequencer Output (SQO)
- 426 Enter an Immediate Mask Value
- 428 Using SQI with SQO
- 428 Resetting the position of SQO
- 429 Sequencer Load (SQL)
- 434 Introduction
- 435 Label (LBL)
- 437 Subroutine (SBR) Return (RET)
- 448 Jump to External Routine (JXR)
- 451 Temporary End (TND)
- 453 Master Control Reset (MCR)
- 455 User Interrupt Disable (UID) User Interrupt Enable (UIE)
- 457 Always False Instruction (AFI)
- 458 No Operation (NOP)
- 459 End of Transition (EOT)
- 461 SFC Pause (SFP)
- 463 SFC Reset (SFR)
- 465 Trigger Event Task (EVENT)
- 465 a Task
- 470 Introduction
- 471 For (FOR)
- 474 Break (BRK)
- 475 Return (RET)
- 478 Introduction
- 479 File Bit Comparison (FBC)
- 481 Selecting the Search Mode
- 487 Diagnostic Detect (DDT)
- 489 Selecting the search mode
- 495 Data Transitional (DTR)
- 496 Enter an immediate mask value
- 498 Proportional Integral Derivative (PID)
- 503 Configure a PID Instruction
- 504 Specify Tuning
- 505 Specify Configuration
- 505 Specifying Alarms
- 506 Specifying Scaling
- 506 Using PID Instructions
- 509 PID instruction timing
- 513 Bumpless Restart
- 514 Derivative Smoothing
- 515 Set the Deadband
- 515 Use Output Limiting
- 516 Feedforward or Output Biasing
- 516 Cascading Loops
- 517 Control a Ratio
- 518 PID Theory
- 518 PID Process
- 518 PID Process With Master/slave Loops
- 520 Introduction
- 521 Sine (SIN)
- 524 Cosine (COS)
- 527 Tangent (TAN)
- 530 Arc Sine (ASN)
- 533 Arc Cosine (ACS)
- 536 Arc Tangent (ATN)
- 540 Introduction
- 541 Natural Log (LN)
- 544 Log Base 10 (LOG)
- 547 X to the Power of Y (XPY)
- 550 Introduction
- 551 Degrees (DEG)
- 554 Radians (RAD)
- 557 Convert to BCD (TOD)
- 560 Convert to Integer (FRD)
- 562 Truncate (TRN)
- 566 Introduction
- 567 Instruction Execution
- 569 ASCII Error Codes
- 569 String Data Types
- 571 ASCII Test For Buffer Line (ABL)
- 574 ASCII Chars in Buffer (ACB)
- 576 ASCII Clear Buffer (ACL)
- 578 ASCII Handshake Lines (AHL)
- 582 ASCII Read (ARD)
- 586 ASCII Read Line (ARL)
- 590 ASCII Write Append (AWA)
- 595 ASCII Write (AWT)
- 600 Introduction
- 601 String Data Types
- 602 String Concatenate (CONCAT)
- 604 String Delete (DELETE)
- 606 Find String (FIND)
- 608 Insert String (INSERT)
- 610 Middle String (MID)
- 612 Introduction
- 614 String Data Types
- 615 String To DINT (STOD)
- 617 String To REAL (STOR)
- 620 DINT to String (DTOS)
- 622 REAL to String (RTOS)
- 624 Upper Case (UPPER)
- 626 Lower Case (LOWER)
- 628 Introduction
- 628 Breakpoints (BPT)
- 629 String Format
- 632 Tracepoints (TPT)
- 632 String Format
- 636 Introduction
- 636 Immediate Values
- 636 Data Conversions
- 638 SINT or INT to DINT
- 640 Integer to REAL
- 640 DINT to SINT or INT
- 641 REAL to an Integer
- 642 Introduction
- 642 Choose the Function Block Elements
- 643 Latching Data
- 645 Order of Execution
- 646 Resolve a Loop
- 648 Resolve Data Flow Between Two Blocks
- 648 Create a One Scan Delay
- 649 Summary
- 649 Function Block Responses to Overflow Conditions
- 650 Timing Modes
- 652 Common Instruction Parameters for Timing Modes
- 654 Overview of Timing Modes
- 655 Program/Operator Control
- 660 Introduction
- 660 Structured Text Syntax
- 662 Assignments
- 663 Specify a non-retentive assignment
- 664 Assign an ASCII character to a string
- 664 Expressions
- 666 Use arithmetic operators and functions
- 667 Use relational operators
- 669 Use logical operators
- 670 Use bitwise operators
- 670 Determine the order of execution
- 671 Instructions
- 672 Constructs
- 672 Some key words are reserved for future use
- 673 IF...THEN
- 676 CASE...OF
- 679 FOR…DO
- 682 WHILE…DO
- 685 REPEAT…UNTIL
- 688 Comments
- 700 ASCII Character Codes