IDEC FT1A Series User Manual page 323

Hide thumbs Also See for FT1A Series:
Table of Contents

Advertisement

Example 1.10 Decimal to octal conversion using a while statement
Script
// 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;
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
switch ([D0100])
{
case 10:
[D0200] = 0x1234;
break;
case 999:
[D0200] = 0x5678;
SET([D0000.01]);
break;
}
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.
S
AXIS P
/L
U
'
MART
RO
ITE
SER
S
M
FT9Y-B1378
ANUAL
13: S
CRIPTS
13-19

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents