26: S
CRIPT
26-22
FC6A S
ERIES
MICROS
MART
L
ADDER
P
ROGRAMMING
M
ANUAL
FC9Y-B1726
Example 1.10
Decimal to octal conversion using a while statement
Script
Operation Description
This example converts a decimal value to octal using a while statement.
By repeating the process to divide the original decimal data by 8 and converting each digit to octal in a while statement, the
conversion is implemented up to four digits.
The original decimal value is stored in D0100. After the script is executed, the converted octal value is stored in D0200.
Example 1.11
Conditional branch with switch
Script
Operation Description
If the value of D0100 is 10, then 0x1234 is stored in D0200.
If the value of D0100 is 999, then 0x5678 is stored in D0200 and D0000.01 is set to 1.
If the value of D0100 is not 10 nor 999, then nothing is executed.
// Convert a decimal value to octal
// - For example, convert 10 (dec) to 12 (oct), 16 (dec) to 20 (oct)
// - Convert a value to octal up to 4 digits max
@1 = 0;
// while counter
@2 = [D0100];
// gets original data
@3 = 1;
// decimal base
@4 = 0;
// calculation results
// repeat four times
while (@1 < 4)
{
// Extract 1st octal digit from original data. Store working result in @10.
@10 = @2 % 8;
//Convert the extracted results to decimal and add to the results
@4 = @4 + (@10 * @3);
//Increase the decimal base by one digit
@3 = @3 * 10;
// Decrease the original data by one digit
@2 = @2 / 8;
// If @2 is 0, exit the white statement
if (0 == @2)
{
break;
}
// Increment while counter by 1
@1 = @1 + 1;
}
// Store the calculation result in D0200
[D0200] = @4;
switch ([D0100])
{
case 10:
[D0200] = 0x1234;
break;
case 999:
[D0200] = 0x5678;
SET([D0000.01]);
break;
}
Summary of Contents for MICROSmart FC6A Series
Page 1: ...B 1726 7 FC6A SERIES Ladder Programming Manual ...
Page 8: ...Preface 7 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 32: ...1 OPERATION BASICS 1 20 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 96: ...3 INSTRUCTIONS REFERENCE 3 18 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 130: ...4 BASIC INSTRUCTIONS 4 34 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 192: ...9 SHIFT ROTATE INSTRUCTIONS 9 12 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 272: ...12 DISPLAY INSTRUCTIONS 12 24 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 284: ...14 REFRESH INSTRUCTIONS 14 6 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 502: ...25 DATA LOG INSTRUCTIONS 25 22 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 546: ...26 SCRIPT 26 44 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...
Page 598: ...APPENDIX A 14 FC6A SERIES MICROSMART LADDER PROGRAMMING MANUAL FC9Y B1726 ...