InBCD Function
Returns the input status of 8 inputs using BCD format. (Binary Coded Decimal)
Syntax
InBCD(portNumber)
Parameters
- portNumber
- Specifies the input byte of I/O.
Return Values
Returns as a Binary Coded Decimal (0-9), the input status of the input port (0 to 99).
Description
InBCD simultaneously reads 8 input lines using the BCD format. The portNumber parameter for the InBCD instruction defines which group of 8 inputs to read where portNumber = 0 means inputs 0 to 7, portNumber = 1 means inputs 8 to 15, etc.
The resulting value of the 8 inputs is returned in BCD format. The return value may have 1 or 2 digits between 0 and 99. The 1st digit (or 10's digit) corresponds to the upper 4 outputs of the group of 8 outputs selected by portNumber. The 2nd digit (or 1’s digit) corresponds to the lower 4 outputs of the group of 8 outputs selected by portNumber.
Since valid entries in BCD format range from 0 to 9 for each digit, every I/O combination cannot be met. The able below shows some of the possible I/O combinations and their associated return values assuming that portNumber is 0.
Input Settings (Input number)
Return Values | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
01 | Off | Off | Off | Off | Off | Off | Off | On |
02 | Off | Off | Off | Off | Off | Off | On | Off |
03 | Off | Off | Off | Off | Off | Off | On | On |
08 | Off | Off | Off | Off | On | Off | Off | Off |
09 | Off | Off | Off | Off | On | Off | Off | On |
10 | Off | Off | Off | On | Off | Off | Off | Off |
11 | Off | Off | Off | On | Off | Off | Off | On |
99 | On | Off | Off | On | On | Off | Off | On |
Notice that the Binary Coded Decimal format only allows decimal values to be specified. This means that through using Binary Coded Decimal format it is impossible to retrieve a valid value if all inputs for a specific port are turned on at the same time when using the InBCD instruction. The largest value possible to be returned by InBCD is 99. In the table above it is easy to see that when 99 is the return value for InBCD, all inputs are not on. In the case of a return value of 99, inputs 0, 3, 4, and 7 are On and all the others are Off.
Note
Difference between InBCD and In
The InBCD and In instructions are very similar in the SPEL+ language. However, there is one major difference between the two. This difference is shown below:
The InBCD instruction uses the Binary Coded Decimal format for specifying the return value format for the 8 inputs. Since Binary Coded Decimal format precludes the values of &HA, &HB, &HC, &HD, &HE or &HF from being used, all combinations for the 8 inputs cannot be satisfied.
The In instruction works very similarly to the InBCD instruction except that In allows the return value for all 8 inputs to be used. (i.e. 0 to 255 vs. 0 to 99 for InBCD) This allows all possible combinations for the 8 bit input groups to be read.
See Also
In, MemOff, MemOn, MemOut, MemSw, Off, On, OpBCD, Oport, Out, Sw, Wait
InBCD Function Example
Some simple examples from the Command window are as follows:
Assume that inputs 0, 4, 10, 16, 17, and 18 are all On (The rest of the inputs are Off).
> Print InBCD(0)
11
> Print InBCD(1)
04
> Print InBCD(2)
07
>