Ladder Logic Swap Function

KronoTech

PLC

Ladder Logic

Basic

Counters

Timer

Arithmetic

Comparison

Functions

ABS

CLR

CPT

SCL

SCP

SQR

SWP

XPY

Trig Functions

RSLogix 5000

Structured Text

HMI

Instruments

SWP - Swap

Swaps the low and high bytes of a specified number of words in a bit, integer, ASCII, or string file.

Example

Swap (aBcDeF) = BaDcFe

Ladder Logic Solution

SWP - SLC 500 Beginners Guide

Before /After Swap

Example

The next 3 words of N7:140

Ladder Logic Solution

SWP - SLC 500 Beginners Guide

Before/After Swap

·

SWP - SLC 500 Beginners Guide

SWP - SLC 500 Beginners Guide

Note

  • Values of N7:140 are in Hexadecimal

Example

Let's say N7:145 contain ABCD (hexadecimal) and we want to separate high byte and the low byte of this word and put them into 2 separate word.

Ladder Logic Solution

Execute an AND instruction on the N7: 145 with FF (Hex) this will result in getting the low byte from N7: 145, and put it in N7: 146.

SWP - SLC 500 Beginners Guide

Now that we got the low byte, we have to swap the word N7:145.

SWP - SLC 500 Beginners Guide

Now we can do another AND instruction with FF (Hex) to get the low byte of the swapped word, and put it in words N7: 147

SWP - SLC 500 Beginners Guide
  • N7:145 = ABCD (Hex)
  • N7:146 = AB
  • N7:147 = CD

Note

  • The source can only be an indexed word address.
  • Bit length (1-128)
  • Integer length (1-128)
  • String length (1-41) (one string only)
  • ASCII length (1-128)

Quick Links

PLC Languages

Ladder Logic
Function Block
Structure Text
SFC
Mnemonic

Ladder Logic

Basic
Counters
Timer
Arithmetic
Comparison
Functions
Trig Functions

Instruments

Switches

HMI

Advantages
Alarms
Trends

Other

Bottle Application